10

I can run all unit tests using the following command:

xcodebuild test -workspace Project.xcworkspace -scheme Scheme -sdk iphonesimulator7.0 -destination platform='iOS Simulator',OS=7.0,name='iPhone Retina (4-inch)'

Is there anything I can pass to this to run individual unit tests/classes in the same way that you can using the Xcode UI?

Cheers.

Michael
  • 2,258
  • 1
  • 23
  • 31

4 Answers4

6

Not that I know of, and it's not on the man page either. But you have such option in the excellent xctool (-only SomeTestTarget:SomeTestClass/testSomeMethod).

Jano
  • 62,815
  • 21
  • 164
  • 192
  • Thanks for the recommendation - unfortunately it appears that xctool doesn't work with XCTests yet. – Michael Oct 12 '13 at 17:39
  • The fix is in a pull request if you are adventurous: https://github.com/facebook/xctool/issues/198 (didn't try it myself). – Jano Oct 12 '13 at 18:13
  • I think my problem is that they've broken Kiwi support now (as I couldn't even get it working using that pull request.) I think your answer is correct however and this is the best option. – Michael Oct 22 '13 at 12:50
4

For those who are using later versions of Xcode (8.0+) and may run across this post in the future (like myself), this is now possible using the -only-testing flag, which is documented in the man page for xcodebuild. The format for using the flag is as follows:

xcodebuild \
    -destination "$DEST" \
    -workspace "$WRKSP" \
    -scheme "$SCHEME" \
    -only-testing:Target/Class/Method test

You can also omit elements from the path after the -only-testing flag, e.g. -only-testing:Scheme/Class will run all these tests within that class.

Here is a related Stackoverflow question, touching on the new functionality: How to use xcodebuild with -only-testing and -skip-testing flag?

Community
  • 1
  • 1
Aaron
  • 596
  • 1
  • 5
  • 15
  • Yep, that's good point, but this was among the first results in multiple searches I made trying to find a solution to this problem. I'll update the answer to clarify! – Aaron Dec 28 '16 at 17:11
  • For anyone who has issues with this, the `-only-testing` argument takes in `Target/Class/Method` NOT `Scheme/Class/Method`. – Liron Yahdav Jan 07 '17 at 01:08
1

Another way is to edit the schemer of your test file and disable/enable the tests as you please. Then you can rerun the same command through the CLI and it will only run the tests you specified above.

enter image description here

TYRONEMICHAEL
  • 4,174
  • 4
  • 30
  • 47
0

If you're using Kiwi, you should supposedly be able to do it using the KW_SPEC environment variable. I haven't been able to, though: Running a single KIWI spec with xctool.

Community
  • 1
  • 1
Ohad Schneider
  • 36,600
  • 15
  • 168
  • 198