Kevin Stembridge Kevin Stembridge - 1 year ago 112
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?



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

Answer Source

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

TestNGOptions options = (TestNGOptions) test.getOptions();
// configure options ie...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download