14

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
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
  • Does this answer your question? [Running a specific instrumentation unit test with Gradle](https://stackoverflow.com/questions/19565857/running-a-specific-instrumentation-unit-test-with-gradle) – tir38 Feb 06 '20 at 00:09
  • Try https://stackoverflow.com/a/49403467/1172181 – Luis Sep 13 '22 at 22:14

1 Answers1

24

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
Juanvi Martinez
  • 291
  • 1
  • 5
  • 4
    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. – Merk Jun 07 '19 at 03:19
  • 10
    tried version 3.6.0, not working. option --tests is not recognized. – eastwater Jun 18 '20 at 20:16
  • 1
    The command in this answer works for me, using Gradle 6.5 and AGP 4.1.2. Also see https://developer.android.com/studio/test/command-line#RunTestsGradle. It's possible to omit the package name and just use the class name. – fejd Feb 15 '21 at 12:30
  • 2
    This does not seem to work for instrumented tests. – Evan Citulsky Jun 24 '21 at 18:57