I noticed that it is easier to create a separate class for a test purpose when the source class performs some asynchronous actions.
Suppose you are writing a test for a UIViewController that has a LoginSystem dependency that uses AFNetworking to execute an API request. LoginSystem takes a block argument as a callback. (UIViewController-> LoginSystem-> AFNetworking).
If you are mistaken in the LoginSystem, you may have problems with how to start the callback block to check if the UIViewController is successful / failed. When I tried, I ended up with MKTArgumentCaptor to get a block argument, and then I had to call it in a test file.
On the other hand, if you create a separate class for LoginSystem (call it LoginSystemStub, which extends from LoginSystem), you can make fun of the behavior in three lines of code and outside the test file. We must also keep the test file clean and readable.
Another thing is that verify () does not work with checking asynchronous behavior. It is much easier to call expect (smth2). will be .equal (smth)
EDIT:
Pointers to NSError (NSError **) also work poorly with verify (), and it is better to create a stub: D
Adam borek
source share