Running tests with different options


(David Grieve) #1

I have a set of Java unit tests that I want to run with a property set to true, and I want to run those test again with the property set to false. In the case of the property being false, I want to exclude a test. Here is what I have. But I think this is running my tests three times. I don’t want the test to run at all without the ‘foo’ property defined.

test {
    dependsOn 'testFooEnabled','testFooDisabled'
    useTestNG()
}

task testFooEnabled(type: Test) {
    systemProperties 'foo': 'true'
}

task testFooDisabled(type: Test) {
    systemProperties 'foo': 'false'
    exclude '**/RequiresFooTest*'
}

How can I construct this so that the tests run once with ‘foo’:‘true’, and once with ‘foo’:‘false’ with RequiresFooTest excluded?


(David Grieve) #2

So I ended up doing this, but there must be a better way!

test {
dependsOn 'testFooDisabled’
useTestNG()
systemProperties ‘foo’: ‘true’
}

task testFooDisabled(type: Test) {
systemProperties ‘foo’: 'false’
exclude ‘**/RequiresFooTest*’
}