如何在用Java编写的自定义插件中配置Gradle TestNGOptions?

时间:2016-11-15 23:38:58

标签: gradle groovy

我正在编写一个自定义Gradle插件,它将创建一个新的Test任务并运行它。我需要在此测试任务上设置一些配置。

插件是用Java编写的,执行Test任务的代码如下所示:

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();

}

我无法弄清楚如何使用Java中的Closure类。

1 个答案:

答案 0 :(得分:1)

最简单的选择就是调用getOptions()并转换为适当的类型。

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