4

I am trying to run just a single Android test case from the command line.

From the IDE I can just right click and run, but from CLI with the following it fails:

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

Error:

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

How can I run a single UNIT TEST method? 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. (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 Answer 1

3

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*"

Sign up to request clarification or add additional context in comments.

3 Comments

i put a updated . section in my question, can you check. the things you mentioned are not working
@j2emanue Hey! Check my updated answer. I believe this should work for you. I think you may just need an extra * at the end of your test name. Try ./gradlew app:usCameraDebugUnitTest --tests "*mySingleTest*" I don't think you need a colon before app, but it wouldn't hurt to add it. ./gradlew :app:usCameraDebugUnitTest --tests "*mySingleTest*"
this one works for me: /gradlew :app:usCameraDebugUnitTest --tests "*mySingleTest", thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.