我找到了一个名为“xctest”的命令行工具,它显然可以在你的项目中运行单元测试。这个可执行文件住在这里:
/Applications/Xcode.app/Contents/Developer/usr/bin/xctest
当我尝试在我的xctest软件包上运行此可执行文件时,我正在使用:
$ ./xctest /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest
但是,我得到以下输出:
Test Suite '(null)' started at 2013-11-14 21:16:45 +0000
Test Suite '(null)' finished at 2013-11-14 21:16:45 +0000.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
据我所知,xctest没有手册页,但在命令行输入./xctest会产生:
Usage: xctest [--test Self | All | None | <TestCaseClassName/testMethodName>] <path of unit to be tested>
特别是,我希望能够在测试类中测试一个特定的方法,这就是我想使用这个xctest命令的原因。
我确实看到有一种方法可以从命令行运行所有测试,如:
$ xcodebuild test -scheme MyApp
这会运行所有单元测试并正常工作(我看到我的单元测试结果,与使用xctest时不同)。但是我对能够从命令行运行单个测试方法很感兴趣,例如:
$ ./xctest --test MyAppTests/testExample /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest
答案 0 :(得分:5)
尽管使用消息说-XCTest是您需要的参数:
xctest -XCTest MyAppTests/testExample testbundle.xctest
要直接调用xctest工作,您可能还需要将DYLD_FRAMEWORK_PATH
和DYLD_LIBRARY_PATH
设置为构建的产品目录。通常,您需要使用与Xcode相同的参数和环境,您可以通过在其中一个测试中放置断点,通过Xcode运行它们,然后打印出arguments
和{{1}的值来看到这一点。 } environment
。
为避免弄乱所有注意事项,您还可以在Xcode中修改方案以仅运行特定测试。在产品&gt;下方案&gt; Edit Scheme选择Test操作并展开测试包。您可以使用复选框选择要运行的测试,然后xcodebuild的测试操作将仅运行这些测试。