Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run single test class in Android using Gradle command?

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
like image 344
M.A.Murali Avatar asked Aug 13 '18 13:08

M.A.Murali


People also ask

How do I run a specific test class in Gradle?

In Gradle, we can pass an --tests option to run a single unit test class.


1 Answers

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
like image 159
Juanvi Martinez Avatar answered Sep 27 '22 18:09

Juanvi Martinez