Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fladle {
"class com.foo.ClassForShard3; package com.package.for.shard3"
]
failFast = true
dependOnAssemble = true
}
```

Expand Down Expand Up @@ -1103,3 +1104,15 @@ Multiple options
other-new-property: force
""".trimIndent())
```

### dependOnAssemble
If true, automatically builds app and test APKs before `runFlank` executes.

=== "Groovy"
``` groovy
dependOnAssemble = false
```
=== "Kotlin"
``` kotlin
dependOnAssemble.set(false)
```
14 changes: 4 additions & 10 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# FAQ

## Error APK file not found
The app APK and the instrumentation APK are expected to have already been generated before calling runFlank.
If you would like the flank task to automatically create the APKs, you can add the following to your application's build.gradle.
```
afterEvaluate {
tasks.named("execFlank").configure {
dependsOn("assembleDebugAndroidTest")
}
}
```
The app APK and the instrumentation APK are expected to have already been generated before calling runFlank. To generate APKs, run `assembleDebug` and `assembleDebugAndroidTest` before running `runFlank`.

You can also have Fladle build them for you by using the [`dependOnAssemble`](../configuration/#dependOnAssemble) property.


See [https://issuetracker.google.com/issues/152240037]() for more information.


## No signature of method
Expand Down
2 changes: 1 addition & 1 deletion fladle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent

group = "com.osacky.flank.gradle"
version = "0.14.2-SNAPSHOT"
version = "0.15.0-SNAPSHOT"
description = "Easily Scale your Android Instrumentation Tests with Firebase Test Lab with Flank"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ interface FladleConfig {
@get:Optional
val additionalFlankOptions: Property<String>

/**
* When enabled, the execution of flank will depend on the Gradle tasks to assemble the debug and instrumentation APKs.
* before flank runs
*/
@get:Input
@get:Optional
val dependOnAssemble: Property<Boolean>

/**
* Allow appending additional config to gcloud root yaml. This option is useful when you would like to test option
* before it is available on Fladle. Supports both single and multiple properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ data class FladleConfigImpl(
override val failFast: Property<Boolean>,
override val maxTestShards: Property<Int>,
override val additionalFlankOptions: Property<String>,
override val additionalGcloudOptions: Property<String>
override val additionalGcloudOptions: Property<String>,
override val dependOnAssemble: Property<Boolean>
) : FladleConfig {
/**
* Prepare config to run sanity robo.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.osacky.flank.gradle

import com.android.build.gradle.AppExtension
import com.android.build.gradle.TestedExtension
import com.android.builder.model.TestOptions
import com.osacky.flank.gradle.validation.checkForExclusionUsage
import com.osacky.flank.gradle.validation.validateOptionsUsed
Expand Down Expand Up @@ -106,6 +107,18 @@ class FladlePluginDelegate {
environment(mapOf("GOOGLE_APPLICATION_CREDENTIALS" to config.serviceAccountCredentials.get()))
}
dependsOn(writeConfigProps)
if (config.dependOnAssemble.isPresent && config.dependOnAssemble.get()) {
project.extensions.findByType(TestedExtension::class.java)?.let { testedExtension ->
testedExtension.testVariants.configureEach {
if (testedVariant.assembleProvider.isPresent) {
dependsOn(testedVariant.assembleProvider.get())
}
if (assembleProvider.isPresent) {
dependsOn(assembleProvider.get())
}
}
}
}
}

register("runFlank$name", RunFlankTask::class.java).configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl

override val additionalGcloudOptions: Property<String> = objects.property()

override val dependOnAssemble: Property<Boolean> = objects.property<Boolean>().convention(false)

@Internal
val configs: NamedDomainObjectContainer<FladleConfigImpl> = objects.domainObjectContainer(FladleConfigImpl::class.java) {
FladleConfigImpl(
Expand Down Expand Up @@ -200,7 +202,8 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl
failFast = objects.property<Boolean>().convention(failFast),
maxTestShards = objects.property<Int>().convention(maxTestShards),
additionalFlankOptions = objects.property<String>().convention(additionalFlankOptions),
additionalGcloudOptions = objects.property<String>().convention(additionalGcloudOptions)
additionalGcloudOptions = objects.property<String>().convention(additionalGcloudOptions),
dependOnAssemble = objects.property<Boolean>().convention(dependOnAssemble)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.osacky.flank.gradle.integration

import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -126,6 +127,67 @@ class FlankGradlePluginIntegrationTest {
assertThat(result.output).contains("debugApk must be specified")
}

private fun setUpDependOnAssemble(dependsOnAssemble: Boolean): BuildResult {
writeBuildGradle(
"""plugins {
id "com.osacky.fladle"
id "com.android.application"
}
repositories {
google()
mavenCentral()
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.osacky.flank.gradle.sample"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}
fladle {
serviceAccountCredentials = project.layout.projectDirectory.file("foo")
dependOnAssemble = $dependsOnAssemble
}
""".trimIndent()
)
testProjectRoot.newFile("foo").writeText("{}")
testProjectRoot.newFolder("src/main")
testProjectRoot.newFile("src/main/AndroidManifest.xml").writeText(
"""
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.osacky.flank.gradle.sample" xmlns:android="http://schemas.android.com/apk/res/android" />
""".trimIndent()
)
val result = GradleRunner.create()
.withProjectDir(testProjectRoot.root)
.withPluginClasspath()
.withArguments("runFlank", "--dry-run")
.build()

return result
}

@Test
fun testWithDependOnAssemble() {
val result = setUpDependOnAssemble(true)
assertThat(result.output).contains(":assembleDebug")
assertThat(result.output).contains(":assembleDebugAndroidTest")
}

@Test
fun testWithOutDependOnAssemble() {
val result = setUpDependOnAssemble(false)
assertThat(result.output).doesNotContain(":assembleDebug")
assertThat(result.output).doesNotContain(":assembleDebugAndroidTest")
}

@Test
fun testMissingInstrumentationApkFailsBuild() {
writeBuildGradle(
Expand Down
1 change: 1 addition & 0 deletions sample-flavors-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fladle {
}
}
flakyTestAttempts.set(1)
dependOnAssemble.set(true)
}

dependencies {
Expand Down