How to run OCUnit logic tests automatically before each build (run) of iOS app in Xcode 4?
Asked Answered
S

1

6

It seems that I have everything set up correctly. When I run command ⌘ + U (or select Product > Test from menu) my test runs fine.

Best practices should be that test are run as often as possible, ideally during each build (understand during each run).

How do I force Xcode 4 to do it? I have tried to:

  • set up a target dependency (put main app target to be dependent on test target)
  • enable a "test after build" in main app target build settings
  • tick also test target in scheme editor for run main app scheme

but nothing seems to work. Does anyone have success setting up this?

Supen answered 8/8, 2011 at 9:22 Comment(2)
Is it necessary to run the unit tests before each build? If you set the Test After Build build setting to Yes and choose Product > Build For > Build For Testing, Xcode builds the project and runs the tests.Adena
yes. But this is the same as I do have now - just whenever press command-u and the tests run. But I am bored to press this often. And I often forget. And then sometimes happens, that I must dig into code and find a bug. Which could have been caught immediately, if I ran the tests with each build. And it is best practice too - run test automatically during each build ("build" I mean every time I want to run the app)Afrikaner
S
10

Finally figured it out, though still not perfect:

  1. On your test target make sure set "Test after build" to yes.
  2. On your main app scheme - build - under "run" tick also test bundle.

This makes your test target build when running the app. Thanks to "Test after build" also the tests run. If everything is ok, app starts in sim. If there are any failing tests, you get a crash, if you use STAssert. In case of OCMock, you can check what exactly went wrong in log inspector.

Sometimes breakpoints do not work. To get them working try product - perform action - test without building.

Supen answered 29/8, 2011 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.