My gradle project already generates two libraries from and idl, and junit unit tests, and compiles some need c++ code. But I’d like to add a integration/verification test that does NOT use a test framework. It is supplied an xml scenario file as a command line parameter and the system.exit status will be non zero on failure.
I’d still like to use the java plugin so that all of the project class path / compile settings are organized and easy vs using the Exec task and needing to put every java build parameter in an args list.
Is this possible? I can’t seem to figure out how to get a test task I setup to see my main and run it.
Ah, the obvious is usually the easiest. That is exactly what I needed. Thanks! Don’t know why I went strait to Exec.
for others that are interested, these are the pertient areas I added to my build.gradle
configurations {
// needed to pass dependencies to the verifyTests sourceSet
compileVerify
}
sourceSets {
main {
java {
srcDir 'generated'
srcDir 'src'
}
resources.srcDir 'resources'
}
test {
java.srcDir 'test'
resources.srcDir 'resources'
}
verifyTests {
java.srcDir 'verificationTests/driver'
resources.srcDir 'resources'
compileClasspath += sourceSets.main.output + configurations.compileVerify
}
}
dependencies {
compileVerify name: 'log4j-api-2.3'
compileVerify name: 'log4j-core-2.3'
compileVerify name: 'log4j-slf4j-impl-2.3'
compileVerify name: 'slf4j-api-1.7.12'
compileVerify name: 'slf4j-ext-1.7.12'
}
// in the verificationTests directory, find all the xml files to process
fileTree(new File(project.rootDir, "verificationTests")).matching{ include '*.xml' }.each { File file ->
// we know this is a .xml file from the filter above, so get the filename without those last 4
// characters, to give the task a reasonable task name
String fullFileName = file
String fileNameSimple = fullFileName.substring(fullFileName.lastIndexOf('/')+1,fullFileName.length()-4)
//create the dynamic task
task "testVerify$fileNameSimple"(type: JavaExec){
File scenarioFile = file
inputs.file new File(project.rootDir, 'driver/Driver.java');
main = "Driver"
args = [ scenarioFile.toString()]
classpath = sourceSets.main.runtimeClasspath + sourceSets.verifyTests.runtimeClasspath + configurations.compileVerify
// run everytime called
outputs.upToDateWhen { false }
}
}