Skip to content

Commit

Permalink
Break up the unit and integration tests into two groups. Allows
Browse files Browse the repository at this point in the history
execution of unit tests once, and integration tests can be executed per
dialect.
  • Loading branch information
philipmarzullo64 committed Nov 4, 2019
1 parent 59231c0 commit 47a9ed0
Show file tree
Hide file tree
Showing 74 changed files with 152 additions and 4 deletions.
21 changes: 21 additions & 0 deletions symmetric-assemble/common.gradle
Expand Up @@ -74,6 +74,9 @@ subprojects { subproject ->
apply plugin: 'propdeps-eclipse'
apply plugin: 'maven'

// Integration test plugin
apply from: "$symAssembleDir/gradle/integrationTest.gradle"

configurations { deployerJars }
configurations { testArtifacts.extendsFrom testRuntime }

Expand All @@ -91,6 +94,10 @@ subprojects { subproject ->
options.compilerArgs += '-Xlint:deprecation'
}

compileIntegrationTestJava {
options.compilerArgs += '-Xlint:deprecation'
}

eclipse {
classpath {
downloadSources = true
Expand Down Expand Up @@ -185,6 +192,20 @@ subprojects { subproject ->
forkEvery=1
}

integrationTest {
ignoreFailures true
systemProperty "test.name", System.getProperty("test.name", "h2")
systemProperty "test.server", System.getProperty("test.server", "h2")
systemProperty "test.client", System.getProperty("test.client", "h2")
systemProperty "test.root", System.getProperty("test.root", "h2")
systemProperty "port.number", System.getProperty("port.number", "31415")
systemProperty "db2i.db.user", System.getProperty("db2i.db.user")
systemProperty "db2i.db.password", System.getProperty("db2i.db.password")
minHeapSize = "128m"
maxHeapSize = "512m"
forkEvery=1
}

jar {
manifest {
attributes("Implementation-Title": project.name,
Expand Down
124 changes: 124 additions & 0 deletions symmetric-assemble/gradle/integrationTest.gradle
@@ -0,0 +1,124 @@
sourceSets {
integrationTest {
// java.srcDir 'src/integrationTest/java'
compileClasspath += sourceSets.main.output
compileClasspath += sourceSets.test.output
// resources.srcDir 'src/integrationTest/resources'
runtimeClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.test.output
}
}

configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
}

dependencies {
// Provides, at compile-time, the classes produced by the main and test SourceSets,
// allowing the integration tests to access the production code in main
// and allowing them to reuse any unit test helper methods in test.
integrationTestImplementation sourceSets.main.output
integrationTestImplementation sourceSets.test.output

// Provides, at compile-time, the dependencies that both
// main and test require in order to successfully compile.
integrationTestImplementation configurations.implementation
integrationTestImplementation configurations.testImplementation

// Provides, at run-time, the dependencies that both
// main and test require to run.
integrationTestRuntimeOnly configurations.runtimeOnly
integrationTestRuntimeOnly configurations.testRuntimeOnly
}

task integrationTest(type: Test) {
// The group and description are useful to define
// as they will be shown to anyone who runs gradle tasks,
// which provides a detailed list of all runnable tasks
// within the project.

group = LifecycleBasePlugin.VERIFICATION_GROUP
description = 'Runs the integration tests.'

// Integration tests are often memory intensive and
// could use an increase in the JVM’s maximum heap size.

// maxHeapSize = '1024m'

// The task requires us to define where both our classes and classpath reside,
// which we can find from the SourceSet we defined previously.

testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath

// We must define the directories in which our test reports are written
// for various formats, e.g. binary, HTML, and XML.

binResultsDir = file("$buildDir/integration-test-results/binary/integrationTest/" + System.getProperty("test.name"))

reports {
html.destination = "$buildDir/reports/integration-test/" + System.getProperty("test.name")
junitXml.destination = "$buildDir/integration-test-results/" + System.getProperty("test.name")
}

// As we want our new task to execute after the unit tests,
// we can use the mustRunAfter ordering rule to ensure that
// whenever both of these tasks are in the same execution
// lifecycle (e.g. when running the check task),
// the unit tests are ran before the integration tests.

mustRunAfter tasks.test


}

// We add our newly created integTest task to the verification
// task lifecycle by making the check task depend upon it.

check.dependsOn integrationTest

// In our task’s definition we ensure that it runs after the test task
// that exists within the same project. However, our project structure
// defines multiple sub-projects for which Gradle will create multiple
// individual test tasks. For this reason we must re-evaluate all of the
// other projects once Gradle has finished the Configuration Phase and
// modify our integrationTest task to run after any fast-failing
// tasks (e.g. test) that were created by other sub-projects.

// We can hook into this part of the build using the projectsEvaluated
// listener which, once triggered, allows us to and iterate over each
// configured project/sub-project to find fast-failing tasks that should
// be prioritized before our integrationTest task within the task execution graph.

gradle.projectsEvaluated {
// We begin by defining an empty list that will contain tasks that are quick-to-execute.

def quickTasks = []

// Then we iterate over every project that is now configured under the rootProject.

gradle.rootProject.allprojects.each { project ->

// Any tasks named test represent the unit tests and are added to the list.

quickTasks.addAll(project.tasks.findAll { it.name == 'test' })

// Tasks whose type are FindBugs or Pmd,
// two static code analysis tools that are quick to analyse
// the entire codebase, are also added.
// We don't use these

// quickTasks.addAll(project.tasks.withType(FindBugs))
// quickTasks.addAll(project.tasks.withType(Pmd))
}

quickTasks.each { task ->
project.tasks.integrationTest.mustRunAfter task
}
}

// Let's add the target directory to clean
cleanIntegrationTest.doLast {
file('target').deleteDir()
}
2 changes: 1 addition & 1 deletion symmetric-client/build.gradle
Expand Up @@ -41,6 +41,6 @@ apply from: symAssembleDir + '/common.gradle'

testCompile project(path: ':symmetric-util', configuration: 'testArtifacts')
testCompile project(path: ':symmetric-io', configuration: 'testArtifacts')
testCompile project(path: ':symmetric-jdbc', configuration: 'testArtifacts')
integrationTestCompile project(':symmetric-jdbc').sourceSets.integrationTest.output
testCompile project(path: ':symmetric-core', configuration: 'testArtifacts')
}
5 changes: 4 additions & 1 deletion symmetric-io/build.gradle
Expand Up @@ -12,5 +12,8 @@ apply from: symAssembleDir + '/common.gradle'

testCompile project(path: ':symmetric-util', configuration: 'testArtifacts')
testCompile project(":symmetric-jdbc")
testCompile project(path: ':symmetric-jdbc', configuration: 'testArtifacts')
integrationTestImplementation project(':symmetric-jdbc').sourceSets.integrationTest.output
integrationTestRuntimeOnly project(':symmetric-jdbc').sourceSets.integrationTest.output
integrationTestRuntimeOnly project(':symmetric-jdbc').sourceSets.test.output

}
4 changes: 2 additions & 2 deletions symmetric-server/build.gradle
Expand Up @@ -34,9 +34,9 @@ apply from: symAssembleDir + '/asciidoc.gradle'

testCompile project(path: ':symmetric-util', configuration: 'testArtifacts')
testCompile project(path: ':symmetric-io', configuration: 'testArtifacts')
testCompile project(path: ':symmetric-jdbc', configuration: 'testArtifacts')
integrationTestCompile project(':symmetric-jdbc').sourceSets.integrationTest.output
testCompile project(path: ':symmetric-core', configuration: 'testArtifacts')
testCompile project(path: ':symmetric-client', configuration: 'testArtifacts')
integrationTestCompile project(':symmetric-client').sourceSets.integrationTest.output
}

distributions {
Expand Down

0 comments on commit 47a9ed0

Please sign in to comment.