“Test After Build” option in XCode 4 not working

2019-03-18 10:41发布

So, I am having a bear of a time figuring this one out. I have looked around, and cannot seem to find any information on this.

What I want to do is have my unit tests ALWAYS run EVERY time I build my code in XCode. I have read a number of posts, including this question here. I have followed the instructions to the letter, and the build will not run the tests.

What I have done:

  • My Test suite is a target dependency of my main build
  • My main build has "Test After Build" set to Yes
  • All of the tests under the "test" phase in the Scheme are there, and checked

If I run the tests manually - through cmd+U or the menu - the tests run. I have added a failing test to try and force the build to fail - so I can be sure they are running. The build continues to pass fine, and the tests are never run.

I am positive I have missed a step in here, but for the life of me I cannot find any documentation related to it. Anyone have any other advice or steps I should be doing?

2条回答
We Are One
2楼-- · 2019-03-18 11:06

It doesn't matter whether or not "Test After Build" is set to yes or no in your Something.app target. It is only necessary to set "Test After Build" to YES in the unit test target. Also make sure that both "Test" and "Run" are selected for your unit test target in the scheme editor under the "Build" tab options. To see the results click on the Log Navigator View > Navigators > Show Log Navigator (command 7).

查看更多
叛逆
3楼-- · 2019-03-18 11:11

In your main target's Build Phases, add a new Run Script build phase. The content of the script should be:

"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"

That will run the tests - but only if it can find the .octest files generated by your project. RunUnitTests wants PRODUCT_NAME to be the name of your unit test, and WRAPPER_EXTENSION to be .octest (these are Xcode variables). If your main target is an aggregate target that has your tests AND your app as dependancies, you can probably make it work with that in mind.

查看更多
登录 后发表回答