Skip to content

Commit

Permalink
Improve test reliability (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Dec 17, 2023
2 parents 2b5e4ff + ee3d66a commit 0bf908c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install JDK ${{ matrix.jre }}
uses: actions/setup-java@v3
with:
Expand All @@ -33,7 +33,7 @@ jobs:
- name: gradlew build
run: ./gradlew build
- name: junit result
uses: mikepenz/action-junit-report@v3
uses: mikepenz/action-junit-report@v4
if: always() # always run even if the previous step fails
with:
check_name: JUnit ${{ matrix.jre }} ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions selfie-runner-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
}
test {
useJUnitPlatform()
getInputs().dir('../undertest-junit5/src/test/kotlin')
}

// it all needs to get published and formatted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import javax.xml.xpath.XPathFactory
import okio.FileSystem
import okio.Path
import okio.Path.Companion.toPath
import org.gradle.internal.impldep.junit.framework.AssertionFailedError
import org.gradle.tooling.BuildException
import org.gradle.tooling.GradleConnector
import org.opentest4j.AssertionFailedError
import org.w3c.dom.NodeList
import org.xml.sax.InputSource

Expand Down Expand Up @@ -174,27 +174,29 @@ open class Harness(subproject: String) {
}
}
fun gradlew(task: String, vararg args: String): AssertionFailedError? {
val runner =
GradleConnector.newConnector()
.forProjectDirectory(subprojectFolder.parent!!.toFile())
.connect()

try {
val buildLauncher =
runner
.newBuild()
.forTasks(":${subprojectFolder.name}:$task")
.withArguments(
buildList<String> {
addAll(args)
add("--configuration-cache") // ControlWR enabled vs disables is 11s vs 24s
add("--stacktrace")
})
buildLauncher.run()
return null
} catch (e: BuildException) {
return parseBuildException(task, e)
}
return GradleConnector.newConnector()
.forProjectDirectory(subprojectFolder.parent!!.toFile())
.connect()
.use { connection ->
try {
val buildLauncher =
connection
.newBuild()
// .setStandardError(System.err)
// .setStandardOutput(System.out)
.forTasks(":${subprojectFolder.name}:$task")
.withArguments(
buildList<String> {
addAll(args)
add("--configuration-cache") // enabled vs disabled is 11s vs 24s
add("--stacktrace")
})
buildLauncher.run()
return null
} catch (e: BuildException) {
return parseBuildException(task, e)
}
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions undertest-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ test {
}
tasks.register('underTest', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// defaults to 'write'
systemProperty 'selfie', findProperty('selfie')
}
tasks.register('underTestRead', Test) {
useJUnitPlatform()
testClassesDirs = testing.suites.test.sources.output.classesDirs
classpath = testing.suites.test.sources.runtimeClasspath
// the snapshots are both output and input, for this harness best if the test just always runs
outputs.upToDateWhen { false }
// read-only
systemProperty 'selfie', 'read'
}

0 comments on commit 0bf908c

Please sign in to comment.