Skip to content

Commit 08e1e7b

Browse files
committed
Disable several "heavy" plugin unit tests if no network access exists
1 parent 5bd97a6 commit 08e1e7b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

android-junit5/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ dependencies {
7979

8080
testCompile "junit:junit:$JUNIT4_VERSION"
8181
testCompile("org.spockframework:spock-core:$SPOCK_VERSION") { transitive = false }
82+
testCompileOnly "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION_3X"
8283
testAgp2xCompile "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION_2X"
8384
testAgp3xCompile "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION_3X"
8485
}

android-junit5/src/test/groovy/de/mannodermaus/gradle/plugins/android_junit5/AndroidJUnitPlatformSpec.groovy

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.gradle.api.internal.plugins.PluginApplicationException
66
import org.gradle.internal.resolve.ModuleVersionNotFoundException
77
import org.gradle.testfixtures.ProjectBuilder
88
import spock.lang.IgnoreIf
9+
import spock.lang.Requires
910
import spock.lang.Specification
1011

1112
/**
@@ -55,6 +56,16 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
5556
return Version.ANDROID_GRADLE_PLUGIN_VERSION.startsWith("3.")
5657
}
5758

59+
private static boolean hasInternetAccess() {
60+
try {
61+
// TODO Easier and/or more lightweight detection method?
62+
return InetAddress.getByName("https://google.com").isReachable(1000)
63+
64+
} catch (UnknownHostException ignored) {
65+
return false
66+
}
67+
}
68+
5869
/* Before Each */
5970

6071
def setup() {
@@ -132,6 +143,8 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
132143
p.tasks.getByName("junitPlatformTestRelease")
133144
}
134145

146+
@SuppressWarnings("UnnecessaryQualifiedReference")
147+
@Requires({ AndroidJUnitPlatformSpec.hasInternetAccess() })
135148
def "classpath assembled correctly"() {
136149
when:
137150
// Prepare another test project to link to
@@ -243,7 +256,9 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
243256
p.tasks.getByName("junitPlatformTestPaidRelease")
244257
}
245258

246-
@IgnoreIf({ isAgp3x() })
259+
@SuppressWarnings("UnnecessaryQualifiedReference")
260+
@IgnoreIf({ AndroidJUnitPlatformSpec.isAgp3x() })
261+
@Requires({ AndroidJUnitPlatformSpec.hasInternetAccess() })
247262
def "custom junit jupiter version"() {
248263
when:
249264
def nonExistentVersion = "0.0.0"
@@ -292,6 +307,7 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
292307
assert expected.message.contains("$nonExistentVersion")
293308
break
294309
}
310+
295311
expected = expected.cause
296312
}
297313

0 commit comments

Comments
 (0)