我正在编写一个自定义的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类。

最佳答案

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

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

关于gradle - 如何在用Java编写的自定义插件中配置Gradle TestNGOptions?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40621659/

10-10 11:12