Android command line - how to run a single unit test method

可紊 提交于 2019-12-24 06:30:05

问题


in android from command line i am trying to run just a single test case. from the IDE it works fine by right click.
But when i try to do it using the following command in CLI IT FAILS:

./gradlew test --tests "com.xyz.b.module.TestClass.testToRun"

i get the following error:

> Unknown command-line option '--tests'.

i guess its a old thread perhaps but i was following here:

Anyway , how can i run my UNIT TEST single method ? i want to emphasis that i want to run a single unit test not instrumentation test from command line.

it should . also be noted my tests are in kotlin and like this:

fun 'i am testing something'(){
//..Arrange
//..Act
//..Assert
}

i guess spaces replaced by underscore right ?

update: i have a camera app. imagine i have a build variant called usCameraDebug. that means united states camera debug. now can you tell me how to run a single test case i called mySingleTest.

i tried this as you mentioned: ./gradlew test --tests "*mySingleTest"

and ./gradlew app:usCameraDebug test --tests "*mySingleTest"

and also: ./gradlew app:usCameraDebugUnitTest --tests "*mySingleTest" but it . does not work. caan you tell me exactly what to type based on my build variant. its in a module called "app" as defaulted.

here is the test i want to run:

package  com.xyz.cameras.parts
    @Test
        fun mySingleTest(){
            assertEquals(12,13)
        }

回答1:


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

Try this pattern -> ./gradlew :<module>:<flavor> --tests "*textThatTestNameContains*"

Example -> ./gradlew :profile:testDebug --tests "*my_profile*" will run this test:

@Test
public void my_profile_pageview()

Additionally, running with --info flag helps to see the tests themselves or --debug for more output. e.g. ./gradlew --info :profile:testDebug --tests "*my_profile*"



来源:https://stackoverflow.com/questions/57057053/android-command-line-how-to-run-a-single-unit-test-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!