Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Gradle. How start specific instrumented test method?

When I want to start specific local unit test (in folder "test") I start (Dev is buildType):

  gradlew testDevUnitTest --tests com.example.StringUtilTest.testMethod

OK. It's work.

But also I want to start specific instrumented test method (in folder "androidTest").

gradlew connectedDevAndroidTest --tests com.example.StringUtilTest.testSelectLanguageFragment

But I get error:

> Unknown command-line option '--tests'.
like image 923
Alexei Avatar asked Feb 28 '17 16:02

Alexei


People also ask

How do I run a specific test in Gradle?

single system property can be used to specify a single test. You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.

What is an instrumented test Android?

Instrumented tests are tests that run on physical devices and emulators, and they can take advantage of the Android framework APIs and supporting APIs, such as AndroidX Test.

What is androidTestImplementation?

androidTestImplementation—The dependency is only available in the androidTest source set. Android source sets are : main: Contains your app code. This code is shared amongst all different versions of the app you can build (known as build variants) androidTest: Contains tests known as instrumented tests.


1 Answers

You can run all tests in a specific test class like this

gradlew connectedDevAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.StringUtilTest

You can run a single test in a specific test class like this

gradlew connectedDevAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.StringUtilTest#testSelectLanguageFragment

More info at https://developer.android.com/studio/test/command-line.html

like image 113
dweebo Avatar answered Oct 27 '22 16:10

dweebo