How to check UIViewControllers during build?

I really believe in testing, but not a very good practitioner. I did a good job of encompassing model objects and programming them in TDD style. I really like it so much that I would like to expand it to the level of my controller, especially subclasses of the UIViewController .

Unfortunately, many UIKit classes do not work in independent tests. However, I am unhappy with the restriction of running my dependent tests on the device. It is very important for me to perform all unit tests before each build, and it seems to me that this is possible and appropriate for the unit test controller code (unlike other types of testing).

My question is this: how do I test the UIViewController so that tests run before each build? I know about several different solutions to this problem, but I don’t know much about the different benefits of each of them.

+6
iphone unit-testing cocoa-touch uiviewcontroller
source share
4 answers

Therefore, I was unhappy with this situation, as it stood, and the answers of Daniel and Ed prompted me to improve the situation. I decided to take matters into my own hands.

I ended up writing a small Cocoa Touch application that, in -applicationDidFinishLaunching, checks the class hierarchy for any SenTestCase subclasses and runs them. Unlike the materials for testing the GoogleToolboxForMac modules, I tried to use as many SenTesting built-in machines as possible, and as a result, this is actually not the case as this code. I have not tested too much without verifying that UILabel fails to test setup without failure (otest really crashes if you try), but it should work.

I posted a source on the Internet like Bitbucket and Github .

+2
source share

In general, if you are stuck in an environmental issue where unconditional testing seems impossible, you can get around it if the benefits are large enough to ensure that you jump through some hoops.

The situation here is a special case of unwanted external dependencies, which I usually solve in my unit tests: #ifdefing from tiny bits of dependent code or by injecting stub classes to populate the expected dependency roles sufficient for my code to be tested.

So, in this particular case, you can create a new source file, linked only in a test suite called "UIKitStubClasses.m" ... inside it, you could realize simple needs to simulate dependent UIKit classes, such as UIViewController, your test links and carefully execute your own logic.

It is important to remember that usually this is not always so much. Tests let you know what you need to implement in the stub, for example, throwing exceptions about unimplemented methods. You simply add what you need to calm errors and test your code, and then your stub class will be sufficient for testing, like any legitimate class of system systems.

+2
source share

Can you not use the tips / techniques on the Chris Hanson blog here: http://chanson.livejournal.com/120263.html

It seems that you probably need to run your application as a test harness, but it seems to be doable. Just because you use an “application” does not mean that you definitely need to do the usual thing that your application does. Alternatively, you can create another target program, which is just a simple dummy application that will download your test packages and run them.

I agree that this may not be perfect, but it looks like it might work, and it seems that it could be automated.

+2
source share

While apple tools have improved over time, they still leave much to be desired. GHUnit is much better, it has a real test runner, and makes it dead just set breakpoints, etc. You can even use all existing SenTests.

Get it on github.

You can create an instance of all UIKit code without any problems. I use it to test UIViewControllers, approve exits, and test behavior.

+1
source share

All Articles