我发现了一个名为“xctest”的命令行工具,它显然可以在您的项目中运行单元测试。此可执行住在这里:如何使用Xcode 5从命令行运行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
谢谢!实际上,我不需要为DYLD_FRAMEWORK_PATH和DYLD_LIBRARY_PATH设置环境变量。我需要确保在Build/Products/Testing中有正确的xctest bundle位置,而不是Build/Products/Debug。所以我的路径如下所示:./xctest -XCTest MyTestClass/testMyTestFunction /Users/username/Library/Developer/Xcode/DerivedData/MyApp-abcdefghikjklmn/Build/Products/Testing/MyAppTests.xctest –
感谢关于禁用测试的提示方案。您可以选择多行并使用空格键切换选择 - 非常有用! – funroll