-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure entire project APKs for additionalTestApks.
This adds a new plugin called `com.osacky.fulladle` which is to be applied at the root of the project. It scans the project's submodules and adds all the apks and test apks to additionalTestApks. References #96
- Loading branch information
1 parent
4f7521f
commit ccbf7f2
Showing
17 changed files
with
336 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Fladle | ||
|
||
The Gradle Plugin for Firebase Test Lab and Flank | ||
Easily scale your Android Instrumentation tests on Firebase Test Lab with Flank. | ||
|
||
### Documentation is at [runningcode.github.io/fladle](https://runningcode.github.io/fladle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
buildSrc/src/main/java/com/osacky/flank/gradle/FulladlePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.osacky.flank.gradle | ||
|
||
import com.android.build.gradle.AppExtension | ||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
/** | ||
* Like the Fladle plugin, but it configures additionalTestApks for the _full_ project. Hence fulladle. | ||
*/ | ||
class FulladlePlugin : Plugin<Project> { | ||
override fun apply(root: Project) { | ||
println(""" | ||
Warning: Fulladle is still in development. It is very likely not to work. | ||
* Report bugs to the Firebase Community slack in #flank or as an issue in the Fladle project. | ||
* Include the output from the printYml task. | ||
""".trimIndent()) | ||
|
||
check(root.parent == null) { "Fulladle must be applied in the root project in order to configure subprojects." } | ||
FladlePluginDelegate().apply(root) | ||
|
||
val flankGradleExtension = root.extensions.getByType(FlankGradleExtension::class) | ||
|
||
root.subprojects { | ||
pluginManager.withPlugin("com.android.application") { | ||
val appExtension = extensions.getByType<AppExtension>() | ||
// Only configure the first test variant per module. | ||
// Does anyone test more than one variant per module? | ||
var addedTestsForModule = false | ||
|
||
// TODO deal with ignored/filtered variants | ||
appExtension.testVariants.configureEach testVariant@{ | ||
if (addedTestsForModule) { | ||
return@testVariant | ||
} | ||
val appVariant = testedVariant | ||
appVariant.outputs.configureEach app@{ | ||
|
||
this@testVariant.outputs.configureEach test@{ | ||
// TODO is this racy? | ||
// If the debugApk isn't yet set, let's use this one. | ||
if (!flankGradleExtension.debugApk.isPresent) { | ||
flankGradleExtension.debugApk.set(root.provider { this@app.outputFile.absolutePath }) | ||
} else { | ||
// Otherwise, let's just add it to the list. | ||
flankGradleExtension.additionalTestApks.add(root.provider { | ||
"- app: ${this@app.outputFile}" | ||
}) | ||
} | ||
// If the instrumentation apk isn't yet set, let's use this one. | ||
if (!flankGradleExtension.instrumentationApk.isPresent) { | ||
flankGradleExtension.instrumentationApk.set(root.provider { this@test.outputFile.absolutePath }) | ||
} else { | ||
// Otherwise, let's just add it to the list. | ||
flankGradleExtension.additionalTestApks.add(root.provider { | ||
" test: ${this@test.outputFile}" | ||
}) | ||
} | ||
addedTestsForModule = true | ||
return@test | ||
} | ||
} | ||
} | ||
} | ||
pluginManager.withPlugin("com.android.library") { | ||
val library = extensions.getByType<LibraryExtension>() | ||
library.testVariants.configureEach { | ||
outputs.configureEach { | ||
flankGradleExtension.additionalTestApks.add(root.provider { | ||
"- test: $outputFile" | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
buildSrc/src/main/resources/META-INF/gradle-plugins/com.osacky.fulladle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=com.osacky.flank.gradle.FulladlePlugin |
32 changes: 32 additions & 0 deletions
32
buildSrc/src/test/java/com/osacky/flank/gradle/integration/FulladlePluginIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.osacky.flank.gradle.integration | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
class FulladlePluginIntegrationTest { | ||
@get:Rule | ||
var testProjectRoot = TemporaryFolder() | ||
|
||
fun writeBuildGradle(build: String) { | ||
val file = testProjectRoot.newFile("build.gradle") | ||
file.writeText(build) | ||
} | ||
|
||
@Test | ||
fun fladleSmokeTest() { | ||
writeBuildGradle( | ||
"""plugins { | ||
| id "com.osacky.fulladle" | ||
|}""".trimMargin() | ||
) | ||
val result = GradleRunner.create() | ||
.withProjectDir(testProjectRoot.root) | ||
.withPluginClasspath() | ||
.withGradleVersion("6.0") | ||
.build() | ||
assertThat(result.output).contains("SUCCESS") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Multi-module testing | ||
|
||
Multi module testing can be done by manually specifying [additionalTestApks](/fladle/configuration/#additionaltestapks) or applying the Fulladle plugin to automacally gather all the additional test apks. | ||
|
||
## Fulladle Plugin | ||
|
||
!!! Warning | ||
Fulladle is still under development and is not guaranteed to work and may change at any moment. | ||
|
||
1. Apply the Fulladle plugin at the root of the project. | ||
|
||
=== "Groovy" | ||
``` groovy | ||
plugins { | ||
id 'com.osacky.fulladle' version '{{ fladle.current_release }}' | ||
} | ||
``` | ||
=== "Kotlin" | ||
``` kotlin | ||
plugins { | ||
id 'com.osacky.fulladle' version '{{ fladle.current_release }}' | ||
} | ||
``` | ||
|
||
2. Configure the Fladle extension. | ||
|
||
===! "Groovy" | ||
``` groovy | ||
fladle { | ||
serviceAccountCredentials = project.layout.projectDirectory.file("flank-gradle-service-account.json") | ||
} | ||
``` | ||
=== "Kotlin" | ||
``` kotlin | ||
fladle { | ||
serviceAccountCredentials.set(project.layout.projectDirectory.file("flank-gradle-service-account.json")) | ||
} | ||
``` | ||
|
||
!!! Warning | ||
If using buildFlavors or testing against a non default variant, Fulladle might not test the variant you are expecting. | ||
|
||
3. Run the tests. | ||
First assemble all your debug apks and test apks. | ||
``` bash | ||
./gradlew assembleDebug assembleDebugAndroidTest | ||
``` | ||
|
||
!!! note | ||
When using flavors, make sure to assemble your buildVariants as well. | ||
|
||
`./gradlew :app:assembleFreeDebug :app:assembleFreeDebugAndroidTest` | ||
|
||
Run Flank! | ||
``` bash | ||
./gradlew runFlank | ||
``` | ||
|
||
|
||
## Troubleshooting | ||
Fulladle isn't ready yet, but we'd love feedback. Please join us in the [Firebase Community Slack](https://firebase.community/) with any feedback you may have. | ||
You can also file [Fladle Github issues](https://github.com/runningcode/fladle/issues). | ||
|
||
When filing a bug report, please include the Flank version number, the Fladle version number and the output of the following: | ||
|
||
`./gradlew printYml` | ||
|
||
`./gradlew runFlank -PdumpShards` | ||
|
||
|
Oops, something went wrong.