Kevin Stembridge Kevin Stembridge - 20 days ago 8
Groovy Question

How to configure Gradle TestNGOptions in a custom plugin written in Java?

I'm writing a custom Gradle plugin that will create a new Test task and run it. I need to set some configuration on this test task.

The plugin is written in Java and the code to execute the Test task looks like this:

private void runSmokeTests() {

Test test = new Test();
test.useTestNG(new Closure(/* What goes in here? */) {
// and here? How do I get hold of TestNGOptions?
});

test.executeTests();

}


I can't figure out how to use the Closure class from Java.

Answer

Simplest option is just to call getOptions() and cast to the appropriate type.

test.useTestNG();
TestNGOptions options = (TestNGOptions) test.getOptions();
// configure options ie...
options.setPreserveOrder(true);