0
votes

I have a Xcode project with a testable target and unit-test target that tests it. Now I can choose the unit-tests target and run the tests. I want the the test will run automatically each time (after) the testable target is being compiled. Is it possible?

2
You mean after each build for the main target you want to run all the unit tests in the testable target?Alex.Pinhasov
@Alex.Pinhasov yes sirSanich
My answer below didn't help you? If it did I would appreciate it if you could mark it as the correct answer, thanks!Alex.Pinhasov

2 Answers

0
votes

Adding a Unit-Test Target to a Scheme Apple Documentation

Before you can add a unit-test target to a scheme, ensure your project if properly configured for unit-testing. See Setting Up Unit-Testing in a Project to learn how.

To add a unit-test target to a scheme:

  1. From the Scheme toolbar menu, choose the scheme to which you want to add the unit-test target.

  2. From the same menu, choose Edit Scheme.

  3. Select the Test action.

  4. In the Test action Info pane, click the Add button.

  5. Select the unit-test target you want to add to the Test action, and

0
votes

Ok so after doing some research this is what I figured out:

1) It is possible.

2) It extends the build time and therefore is wouldn't recommend it.

3) For some reason, it required me to switch back to "Legacy Build System". enter image description here

How to switch to "Legacy Build System":

File -> Workspace Settings -> Build System

4) If you have a dependencies between your product scheme and the test scheme be sure to remove it. enter image description here

How to make it work:

According to the documentation https://developer.apple.com/library/archive/technotes/tn2339/_index.html you can use "xcodebuild" and add a "Run Script" to build the tests scheme.

To add a script go to your project settings -> Build Phases -> "+" -> paste the code below and change the "myWorkspace" to your workspace name and "myWorkspaceTests" to your tests scheme name

echo "Unit-Test are about to start: 🎺 Started running myTests 🎺"

xcodebuild test -workspace <myWorkspace>.xcworkspace -scheme '<myWorkspaceTests>' -destination 'platform=iOS Simulator,name=iPhone X,OS=11.4'

enter image description here