Closed corban123 closed 3 years ago
Without a better look at the code I really can't say exactly why. That said, keep in mind that Xcode is running your unit tests by running your application, and it could well be that something in your app wants a ServiceA and now can't find one.
I'd suggest looking at the call stack when the crash occurs and seeing what's going on at that point in time.
Apologies for the word spaghetti that is the title, however, best I got.
I have ClassA and ClassB
Class A
@Inject
ServiceA
Class B also
@Inject
ServiceA
in the Unit Test for ClassA, we initialize a
mockServiceA
andResolver.services.register { mockServiceA as ServiceA }
in the Unit Test for ClassB, we don't care about
ServiceA, so we do not mock and register
ServiceA`.Upon running all my unit tests, ClassA's unit tests are run first, and on tearDown, we deinitialize the mockServiceA we initialized in SetUp.
When ClassB's unit tests are run, I immediately receive a
Unexpectedly found nil while implicitly unwrapping an Optional value
, which points to theResolver.services.register { mockServiceA as ServiceA }
fromClassA's
unit tests wheremockServiceA
is what is now nil.My question is why is this happening, and what is the proper way of handling this?