[英]How to run a single unit test method from command line while targeting a specific Gradle build flavor
I am trying to run just a single Android test case from the command line.我试图从命令行只运行一个 Android 测试用例。
From the IDE I can just right click and run, but from CLI with the following it fails:在 IDE 中,我可以右键单击并运行,但是在 CLI 中,它会失败:
./gradlew test --tests "com.xyz.b.module.TestClass.testToRun"
Error:错误:
> Unknown command-line option '--tests'.
How can I run a single UNIT TEST method?如何运行单个 UNIT TEST 方法? I want to emphasis that I want to run a single unit test, not an instrumentation test from command line.
我想强调的是,我想运行单个单元测试,而不是来自命令行的仪器测试。
Update : I have a camera app.更新:我有一个相机应用程序。 Imagine that I have a build variant called
usCameraDebug
.想象一下,我有一个名为
usCameraDebug
的构建变体。 (That means united states camera debug) Now can you tell me how to run a single test case i called mySingleTest
? (这意味着美国相机调试)现在你能告诉我如何运行一个名为
mySingleTest
吗?
I tried this as you mentioned: ./gradlew test --tests "*mySingleTest"
我像你提到的那样试过这个:
./gradlew test --tests "*mySingleTest"
and ./gradlew app:usCameraDebug test --tests "*mySingleTest"
和
./gradlew app:usCameraDebug test --tests "*mySingleTest"
and also: ./gradlew app:usCameraDebugUnitTest --tests "*mySingleTest"
but it .还有:
./gradlew app:usCameraDebugUnitTest --tests "*mySingleTest"
但它 . does not work.不起作用。 caan you tell me exactly what to type based on my build variant.
您可以根据我的构建变体准确地告诉我要键入的内容。 its in a module called "app" as defaulted.
默认情况下,它位于名为“app”的模块中。
Here is the test I want to run:这是我要运行的测试:
package com.xyz.cameras.parts
@Test
fun mySingleTest(){
assertEquals(12,13)
}
You need to specify a wildcard in the pattern while looking for the test name, and make sure to use module + flavor.在查找测试名称时,您需要在模式中指定通配符,并确保使用模块 + 风味。
--tests
will not work with ./gradlew test
or ./gradlew check
--tests
不适用于./gradlew test
或./gradlew check
Try this pattern -> ./gradlew :<module>:<flavor> --tests "*textThatTestNameContains*"
试试这个模式 ->
./gradlew :<module>:<flavor> --tests "*textThatTestNameContains*"
Example -> ./gradlew :profile:testDebug --tests "*my_profile*"
will run this test:示例 ->
./gradlew :profile:testDebug --tests "*my_profile*"
将运行此测试:
@Test
public void my_profile_pageview()
Additionally, running with --info
flag helps to see the tests themselves or --debug
for more output.此外,使用
--info
标志运行有助于查看测试本身或--debug
以获取更多输出。 eg ./gradlew --info :profile:testDebug --tests "*my_profile*"
例如
./gradlew --info :profile:testDebug --tests "*my_profile*"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.