我发现了一个名为"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
发布于 2013-11-15 23:13:59
无论用法消息说什么,-XCTest都是您需要的参数:
xctest -XCTest MyAppTests/testExample testbundle.xctest
要直接调用xctest,您可能还需要将DYLD_FRAMEWORK_PATH
和DYLD_LIBRARY_PATH
设置为您的构建产品目录。一般来说,您需要使用与Xcode相同的参数和环境,您可以通过在测试中放置断点,通过Xcode运行它们,然后为[NSProcessInfo processInfo]
输出arguments
和environment
的值来查看这一点。
为了避免弄乱所有的注释,您还可以修改Xcode中的方案,使其只运行特定的测试。在Product > Scheme > Edit Scheme下,选择Test操作并展开测试包。您可以使用复选框来选择要运行的测试,然后xcodebuild的测试操作将只运行这些测试。
https://stackoverflow.com/questions/19988723
复制相似问题