如何使用 Xcode 5 从命令行运行 xctest? [英] How do I run xctest from the command-line with Xcode 5?

查看:29
本文介绍了如何使用 Xcode 5 从命令行运行 xctest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个名为xctest"的命令行工具,它显然可以在您的项目中运行单元测试.这个可执行文件在这里:

I found a command-line tool called "xctest" that apparently can run the unit tests in your project. This executable lives here:

/Applications/Xcode.app/Contents/Developer/usr/bin/xctest

当我尝试在我的 xctest 包上运行这个可执行文件时,我正在使用:

When I try to run this executable on my xctest bundle, I'm using:

$ ./xctest /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

但是,我得到以下输出:

However, I get the following output:

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 会产生:

There's no man page for xctest, as far as I can tell, but entering just ./xctest at the command-line yields:

Usage: xctest [--test Self | All | None | <TestCaseClassName/testMethodName>] <path of unit to be tested>

特别是,我希望能够仅测试测试类中的特定方法,这就是我想使用此 xctest 命令的原因.

In particular, I'd like to be able to test just a particular method in a test class, which is why I'd like to use this xctest command.

我确实看到有一种方法可以从命令行运行所有测试,例如:

I do see that there is a way to run all the tests from the command line like:

$ xcodebuild test -scheme MyApp

这会运行所有单元测试并正常工作(我看到了我的单元测试结果,与使用 xctest 时不同).但我对能够从命令行运行单个测试方法感兴趣,例如:

This runs all the unit tests and works properly (I see my unit test results, unlike when using xctest). But I'm interested in being able to run a single test method from the command-line, such as:

$ ./xctest --test MyAppTests/testExample  /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

推荐答案

尽管使用消息说的是 -XCTest 是您需要的参数:

Despite what the usage message says -XCTest is the argument you need:

xctest -XCTest MyAppTests/testExample testbundle.xctest

要直接调用 xctest 工作,您可能还需要将 DYLD_FRAMEWORK_PATHDYLD_LIBRARY_PATH 设置为您构建的产品目录.一般来说,您需要使用与 Xcode 相同的参数和环境,您可以通过在其中一个测试中放置一个断点,通过 Xcode 运行它们,然后打印出 arguments 和 <[NSProcessInfo processInfo] 的代码>环境.

For a direct invocation of xctest to work you may also need to set DYLD_FRAMEWORK_PATH and DYLD_LIBRARY_PATH to your built products directory. In general you need to use the same arguments and environment as Xcode does, you can see this by putting a breakpoint in one of your tests, running them through Xcode, then printing out the values of arguments and environment for [NSProcessInfo processInfo].

为了避免弄乱所有注释,您还可以修改 Xcode 中的方案以仅运行特定测试.在产品 > 方案 > 编辑方案下,选择测试操作并展开测试包.您可以使用复选框来选择要运行的测试,然后 xcodebuild 的测试操作将仅运行这些测试.

To avoid messing with all that note you can also modify the scheme in Xcode to run only specific tests. Under Product > Scheme > Edit Scheme select the Test action and expand the test bundle. You can use the check boxes to select the tests to run and xcodebuild's test action will then run only these tests.

这篇关于如何使用 Xcode 5 从命令行运行 xctest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆