16

In my Android application I have several test classes. If I run following command ./gradlew connectedAndroidTest it runs all the test cases inside the android test folder and generate test report for all test classes but I need to test a specific test class and generate report for the test class I tried with the following command:

./gradlew test --tests com.login.user.UserLoginTest

The above command throws following exception

FAILURE: Build failed with an exception.

* What went wrong:
Problem configuring task :app:test from command line.
> Unknown command-line option '--tests'.

* Try:
Run gradlew help --task :app:test to get task usage details. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org


My app gradle version is 3.3
2

1 Answer 1

26

It's possible that you are getting this error if you have multiple flavours in your project. Instead of using just test, try a specific test task:

./gradlew testDebugUnitTest --tests com.login.user.UserLoginTest
Sign up to request clarification or add additional context in comments.

4 Comments

Generally you will also need to specify the module the test is in, e.g., ./gradlew :app:testDebugUnitTest --tests com.login.user.UserLoginTest for the app module.
tried version 3.6.0, not working. option --tests is not recognized.
The command in this answer works for me, using Gradle 6.5 and AGP 4.1.2. Also see developer.android.com/studio/test/command-line#RunTestsGradle. It's possible to omit the package name and just use the class name.
This does not seem to work for instrumented tests.

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.