Reputation: 5658
Is it possible to run a single test class using the new Android gradle build framework?
I have a test package that has multiple test classes (All of them are InstrumentationTestCase classes). I've been able to setup my build.gradle file to run the test package
defaultConfig{
testPackageName "com.company.product.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
But is there a way to test only one test case in that package? Otherwise I'll be using the age old adb shell am instrument -w .......
P.S. I don't have time right now to switch to Roboelectric, but I do see that its pretty much the defacto framework nowadays.
Upvotes: 8
Views: 1444
Reputation: 645
As answered in https://stackoverflow.com/a/32603798 there is now
android.testInstrumentationRunnerArguments.class
Upvotes: 3
Reputation: 975
Using android.test.InstrumentationTestRunner
no, this is not possible. You do, however, have options:
android.test.InstrumentationTestRunner
buildConfigField 'String', 'TEST_NAME', '${testName}'
, where testName
is '"${project.properties.get("test")}"'
if set, otherwise nulltestInstrumentationRunner
with your custom runner./gradlew connectedCheck -Ptest=com.example.Test.testSomething
Spoon is an excellent test runner extension that, among other things (like beautiful multi-device test reports), lets you run individual tests. Since you're using gradle, I recommend the Spoon Gradle Plugin, which has an example of exactly what you want to do in its README.
With the addition of unit testing support, Android now supports running individul unit tests.
This is just an anchor task, actual test tasks are called
testDebug
andtestReleas
e etc. If you want to run only some tests, using thegradle --tests
flag, you can do it by running./gradlew testDebug --tests='*.MyTestClass'
.
Edit: I should also add that Spoon is a drop-in replacement for running tests. You will not have to modify anything but a few lines in your build script to use it.
Upvotes: 4