--tests optionYou can specify the target test class (HogeTest) as follows
./gradlew test --tests com.example.HogeTest
It is also possible to specify the method
./gradlew test --tests com.example.HogeTest.fooMethodTest
You can also specify multiple tests using wildcards (*)
./gradlew test --tests com.example.\*Test
This option allows you to specify "tests to run", but not "tests not to run".
There is also an option called -Dtest.single, but it can be replaced with --tests.
 / ʻexclude functionYou can specify tests to include / exclude in the test target
test {
    include 'com/example/HogeTest.class'
    exclude '**/*Foo*'
}
Unlike --tests, specify the path to the .class file.
Test Grouping
By writing in build.gradle, you can include / exclude tests belonging to a specific category.
test {
    useJUnit {
        includeCategories 'com.example.CategoryA'
        excludeCategories 'com.example.CategoryB', 'com.example.CategoryC'
    }
}
Category is created as Interface and specified through @Category annotation
interface MyCategory
@Category(MyCategory::class)
class HogeTest {
    // some tests...
}
By the way, when I used this, the test with @RunWith (JUnitRunner :: class) was not recognized (mystery).
On Android, describe the settings in the following block of build.gradle
android {
    unitTests.all {
        // here
    }
}
Recommended Posts