Skip to content

Commit

Permalink
Merge pull request #118 from Banno/testBuildType
Browse files Browse the repository at this point in the history
Support non-default testBuildType
  • Loading branch information
joshschriever authored Sep 1, 2022
2 parents 01d1185 + dee37f3 commit f6b74f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,14 @@ In this example, the AndroidX `AndroidJUnitRunner` will be used, animations will
## Running

#### Tasks
Gordon registers a Gradle task for each tested variant, stripping `Debug` from the task name because it's redundant.
Gordon registers a Gradle task for each tested variant, stripping `testBuildType` (normally `Debug`) from the task name because it's redundant.

For example, if you have no flavors defined, the following task is registered:
- `gordon` - the equivalent of `connectedDebugAndroidTest`

If you have a `mode` dimension with `demo` and `full` flavors, plus a `staging` build type in addition to the standard `debug` and `release` types, the following tasks are registered:
- `gordonDemo` - the equivalent of `connectedDemoDebugAndroidTest`
- `gordonFull` - the equivalent of `connectedFullDebugAndroidTest`
- `gordonDemoStaging` - the equivalent of `connectedDemoStagingAndroidTest`
- `gordonFullStaging` - the equivalent of `connectedFullStagingAndroidTest`
If you have a `mode` dimension with `demo` and `full` flavors, plus a `staging` build type in addition to the standard `debug` and `release` types, and you set your `testBuildType` to `staging`, the following tasks are registered:
- `gordonDemo` - the equivalent of `connectedDemoStagingAndroidTest`
- `gordonFull` - the equivalent of `connectedFullStagingAndroidTest`

#### Filtering
There is a `--tests` commandline option that overrides the `testFilter` set in the `gordon` extension if both are specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class GordonPlugin : Plugin<Project> {

fun registerGordonTask(
androidTestVariant: AndroidTest,
testBuildType: String,
configuration: (GordonTestTask) -> Unit
) {
val variantTaskName = androidTestVariant.name
.capitalize(Locale.ROOT)
.replace(Regex("AndroidTest$"), "")
.replace(Regex("Debug$"), "")
.replace(Regex("${testBuildType.capitalize(Locale.ROOT)}$"), "")

project.tasks.register<GordonTestTask>("gordon$variantTaskName") {
group = VERIFICATION_GROUP
Expand Down Expand Up @@ -102,7 +103,7 @@ class GordonPlugin : Plugin<Project> {
when (androidPlugin) {
is AndroidPlugin.App -> androidPlugin.componentsExtension.onVariants { applicationVariant ->
applicationVariant.androidTest?.let { androidTestVariant ->
registerGordonTask(androidTestVariant) { gordonTask ->
registerGordonTask(androidTestVariant, testedExtension.testBuildType) { gordonTask ->
val testedVariant = testedExtension.testVariants.single { it.name == androidTestVariant.name }.testedVariant as ApkVariant

configureGordonTask(
Expand All @@ -121,7 +122,7 @@ class GordonPlugin : Plugin<Project> {
}
is AndroidPlugin.DynamicFeature -> androidPlugin.componentsExtension.onVariants { dynamicFeatureVariant ->
dynamicFeatureVariant.androidTest?.let { androidTestVariant ->
registerGordonTask(androidTestVariant) { gordonTask ->
registerGordonTask(androidTestVariant, testedExtension.testBuildType) { gordonTask ->
val testedVariant = testedExtension.testVariants.single { it.name == androidTestVariant.name }.testedVariant as ApkVariant

val (appProject, appVariant) = appDependencyOfFeature(project, testedVariant)
Expand All @@ -145,7 +146,7 @@ class GordonPlugin : Plugin<Project> {
}
is AndroidPlugin.Library -> androidPlugin.componentsExtension.onVariants { libraryVariant ->
libraryVariant.androidTest?.let { androidTestVariant ->
registerGordonTask(androidTestVariant) { gordonTask ->
registerGordonTask(androidTestVariant, testedExtension.testBuildType) { gordonTask ->
val testedVariant = testedExtension.testVariants.single { it.name == androidTestVariant.name }.testedVariant

configureGordonTask(
Expand Down

0 comments on commit f6b74f6

Please sign in to comment.