是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

时间:2021-01-02 01:20:37

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?

有没有什么我可以传递到这个来运行单个单元测试/类,就像你可以使用Xcode UI一样?

Cheers.

4 个解决方案

#1


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).

不是我所知道的,也不在手册页上。但是你在优秀的xctool中有这样的选择(-only SomeTestTarget:SomeTestClass / testSomeMethod)。

#2


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:

对于那些使用更高版本的Xcode(8.0+)并且将来可能会遇到这篇文章的人(比如我自己),现在可以使用-only-testing标志,该标志记录在xcodebuild的手册页中。使用该标志的格式如下:

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.

您还可以在-only-testing标志之后省略路径中的元素,例如-only-testing:Scheme / Class将在该类中运行所有这些测试。

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

这是一个相关的*问题,涉及新功能:如何使用xcodebuild与-only-testing和-skip-testing标志?

#3


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.

另一种方法是编辑测试文件的阴影,并根据需要禁用/启用测试。然后,您可以通过CLI重新运行相同的命令,它只会运行您在上面指定的测试。

是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

#4


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.

如果你正在使用Kiwi,你应该可以使用KW_SPEC环境变量来做到这一点。但是,我无法使用xctool运行单个KIWI规范。

#1


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).

不是我所知道的,也不在手册页上。但是你在优秀的xctool中有这样的选择(-only SomeTestTarget:SomeTestClass / testSomeMethod)。

#2


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:

对于那些使用更高版本的Xcode(8.0+)并且将来可能会遇到这篇文章的人(比如我自己),现在可以使用-only-testing标志,该标志记录在xcodebuild的手册页中。使用该标志的格式如下:

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.

您还可以在-only-testing标志之后省略路径中的元素,例如-only-testing:Scheme / Class将在该类中运行所有这些测试。

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

这是一个相关的*问题,涉及新功能:如何使用xcodebuild与-only-testing和-skip-testing标志?

#3


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.

另一种方法是编辑测试文件的阴影,并根据需要禁用/启用测试。然后,您可以通过CLI重新运行相同的命令,它只会运行您在上面指定的测试。

是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

#4


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.

如果你正在使用Kiwi,你应该可以使用KW_SPEC环境变量来做到这一点。但是,我无法使用xctool运行单个KIWI规范。