Skip to content

Commit 544e7b3

Browse files
authored
Merge pull request #696 from SimonMarquis/patch/androidTests
Disable unnecessary Android instrumented tests
2 parents c746b6a + 57d1bed commit 544e7b3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.configureFlavors
2020
import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
2121
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
2222
import com.google.samples.apps.nowinandroid.configurePrintApksTask
23+
import com.google.samples.apps.nowinandroid.disableUnnecessaryAndroidTests
2324
import org.gradle.api.Plugin
2425
import org.gradle.api.Project
2526
import org.gradle.api.artifacts.VersionCatalogsExtension
@@ -44,6 +45,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
4445
}
4546
extensions.configure<LibraryAndroidComponentsExtension> {
4647
configurePrintApksTask(this)
48+
disableUnnecessaryAndroidTests(target)
4749
}
4850
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
4951
configurations.configureEach {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.samples.apps.nowinandroid
18+
19+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
20+
import org.gradle.api.Project
21+
22+
/**
23+
* Disable unnecessary Android instrumented tests for the [project] if there is no `androidTest` folder.
24+
* Otherwise, these projects would be compiled, packaged, installed and ran only to end-up with the following message:
25+
*
26+
* > Starting 0 tests on AVD
27+
*
28+
* Note: this could be improved by checking other potential sourceSets based on buildTypes and flavors.
29+
*/
30+
internal fun LibraryAndroidComponentsExtension.disableUnnecessaryAndroidTests(
31+
project: Project,
32+
) = beforeVariants {
33+
it.enableAndroidTest = it.enableAndroidTest
34+
&& project.projectDir.resolve("src/androidTest").exists()
35+
}

0 commit comments

Comments
 (0)