4

I understand that a similar question was asked before, however the provided answer does not cover XCode 5. I understand that the TEST_AFTER_BUILD setting is obsolete in XCode 5 (see unit testing - RunUnitTests error after XCode 5 update) This naturally leads to my question: how exactly do I automate unit testing after each build, now that the setting is obsolete.

Very specifically:

  • I have several (more than 10) projects in my workspace.
  • When I press the RUN button in Xcode 5 (top left in UI), I want unit tests to run for ALL dependencies in the current scheme (assuming of course that related projects have been modified).
  • Additionally, if ANY of the tests would fail, the build and run action should fail.

This was working in XCode 4; see link above to understand how the 'old way to do it' is now broken.

This is a MIGRATION issue. I do not need a general (and possibly out of date) tutorial on unit testing in XCode.

Community
  • 1
  • 1
  • hope my answer helped you.. – Nithin Michael Dec 16 '13 at 09:15
  • ⌘U from Xcode, or xcodebuild test from console. – Jano Dec 16 '13 at 10:35
  • @Jano ⌘U runs the tests manually, I want tests to run automatically and updated my question to improve clarity. As to how to use xcodebuild test, or whether it would help resolve the issue... (?) –  Dec 16 '13 at 12:38
  • Have created a radar to track this http://openradar.appspot.com/15859153 – qnoid Jan 20 '14 at 17:29
  • @qnoid No, you have not. You have created a 'radar' for an unrelated issue. Please do not misquote my question as related to the issue you are describing. Why are you doing this? –  Jan 22 '14 at 03:23
  • @tea you are right, this isn't the correct radar as I decided to split the issue to separate reports. – qnoid Jan 22 '14 at 12:32

3 Answers3

1

I maybe have a useful link for you:
http://meandmark.com/blog/2013/09/xcode-5-unit-testing-changes/
specially the part: XCTest

This was working in XCode 4; see link above to understand how the 'old way to do it' is now broken.

You point to a possible solution for Xcode 5, even if I don't know if its a proper answer. Maybe you should point out your problem a little closer...



And your working with the test scheme of your project? Have you tried to configure the right Pre-action and checked your test settings?

enter image description here

zero3nna
  • 2,524
  • 28
  • 28
  • I do not point at a possible solution for Xcode 5, only for XCode 4... Checked link provided, seen it before, nothing helpful there. –  Dec 18 '13 at 03:20
  • Yes, if you look at my provisional answer to the question, it relies on the scheme's test action (I can run the test action manually and this works fine). –  Dec 21 '13 at 08:33
  • But what makes you think a pre-action defined as part of test action would help at all? By the way the output of pre/post action will not show in XCode. Further, although you can run test action as post-action to build or run, failing tests will not break your build/run action. Okay so if the output of pre/post-action does not show in Xcode, how do I even know that? Because this can be tested with xcodebuild. –  Dec 21 '13 at 08:41
  • sry, I totaly missunderstand your problem before. I found a deep intro to the migration to xcode 5 here: http://stackoverflow.com/questions/20022512/how-do-i-migrate-from-sentestingkit-ocunit-to-xctest. is there not maybe a good starting point for a migration? if not, ignore me and I will stop answering anything to this thread. ;) – zero3nna Dec 21 '13 at 11:14
  • not a bad thing to read but the conclusion of the migration blurb matches what I say in my answer - "The final solution is not as good as in Xcode 4.x where the unit tests were executed automatically every time that I ran the main target's "Run" or "Build" action. Unfortunately, it seems that I can't get this to work without a "Run Script" build phase." - instead of going trigger happy and suggesting I should ignore you, why not take the time to understand the problem? (not a rhetorical question) –  Dec 21 '13 at 11:44
  • ok I now have clearly understand your problem after a research and I will also try to fix this by my own. hopefully I can leave a proper answere soon. – zero3nna Dec 21 '13 at 12:37
1

While I really hope for something more streamlined and better integrated, the closest I got to fixing the above is:

  • adding a build-phase to the project containing our app (keep in mind we have a workspace containing several projects, most of these projects generate libraries needed by our app)
  • the build phase calls "xcodebuild test" from within xcode (see below)

To add a build phase, open the target we are adding a build phase to, then use the menu item:

editor > add build phase > add run script build phase

The custom script calling xcodebuild looks like this:

cd DIR
xcodebuild -workspace MY_WORKSPACE.xcworkspace -scheme MY_SCHEME -destination ‘platform=iOS Simulator,name=iPhone’ test
...

where: DIR - the directory containing my workspace.
... - repeat command invocation for every library being tested.

( Added some info on my blog )

This is far from perfect but for lack of anything better, it does a job. Thanks for posting if you have a better solution.

  • This doesn't seem to work in Xcode 6. It seems to create an infinite loop of running xcodebuild. Also, where would I view the output from the xcodebuild command? – Adam Johns Jun 06 '15 at 00:39
  • If this is running (or failing, even) you should see it where you would normally look for Xcode build output. Having said that, consider using a CI solution instead. This never worked very well in Xcode 5, let alone Xcode 6 –  Jun 07 '15 at 02:24
0

Select the project from the project navigator to open the project editor. Select the project or target on the left side of the project editor. Click the Build Settings button at the top of the editor. The Test After Build build setting is in the Unit Testing collection. Then Set the Test After Build build setting to Yes. Choose Product > Build For > Build For Testing to build the project and run the tests. I got this form the answer to a similar question here.

And please see this tutorial for beggining automated testing.

Community
  • 1
  • 1
Nithin Michael
  • 2,101
  • 11
  • 27
  • 50
  • its still there `Product > Test` or `Product > Build For > Testing`, Shortcuts listed in each tab. – zero3nna Dec 16 '13 at 11:15
  • Nitin, this used to work in Xcode 4; as pointed by Jano this setting has been (purposefully) removed from XCode 5. Further, as explained in my question attempting to use this setting (e.g. using a custom flag) will break the build. My question specifically targets Xcode 5 so thanks for taking the time to reply but it does not help at all. –  Dec 16 '13 at 12:34
  • Ok..I will definitely tell you if i found any solution. – Nithin Michael Dec 16 '13 at 12:48