Gradle和TestNG的Intellij设置

时间:2015-05-04 20:13:54

标签: java gradle testng intellij-14

我开始在Intellij中使用selenium和TestNG(Java基础语言)创建一组测试。我能够在IntelliJ中编译和运行,但是当我添加一个gradle文件(如下所示)时,我遇到了一些编译路径错误。

摇篮:

    apply plugin: 'java'


dependencies {

    testCompile(group: 'org.uncommons', name: 'reportng', version: '1.1.4') {
        exclude(module: 'testng')
    }

    testCompile group: 'com.google.inject', name: 'guice', version: '3.0'
    compile group: 'xml-apis', name: 'xml-apis', version:'1.4.01'

}

configurations.all {
    resolutionStrategy {
        force 'xml-apis:xml-apis:1.4.01'
    }
}

task testfeature1(type: Test) {
    ignoreFailures = true
    useTestNG() {
        suites 'Resources/Dashboards/feature1_testng.xml'
        useDefaultListeners = false
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
    }
}

终端输出:

13:51:08.287 [DEBUG] 

[org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':testfeature1'
13:51:08.301 [INFO] [org.gradle.api.internal.file.collections.DirectoryFileTree] file or directory '/Users/******/Workspace/TestNG_Automation/build/classes/test', not found
13:51:08.301 [INFO] [org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter] Skipping task ':testfeature1' as it has no source files.

我猜Intellij将文件编译到out文件夹,正如我现在看到的那样,但没有构建文件夹。如何更改此项以使gradle和Intellij以相同的方式工作?

1 个答案:

答案 0 :(得分:0)

让我举一个我正在研究的另一个示例项目: https://github.com/virenv/ParallelReporter

在build.gradle的顶部,它的配置如下:

var SHOWBOX = function () {
      var a = $('#box').html();
      var dstDiv = $('#visibleBox');
      // apply margin for the first equation
      dstDiv.css({"margin-top":"2px"});
      dstDiv.html(a);
 }


var SHOWBOX_FADE = function () {
      var a = $('#box').html();
      var dstDiv = $('#visibleBox');
      var fadeDiv = $('#fadeBox');

    fadeDiv.html(a).fadeOut();
    fadeDiv.fadeIn(500,function() {
       dstDiv.html(a);
      // remove the margin for the second equation
       dstDiv.css({"margin-top":"0"});
             fadeDiv.hide();
    });
}

然后使用以下命令设置项目:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'

如果您正在测试输出到 / out ,那么您可能正在以TestNG运行测试,而不是从Gradle执行程序运行。如果您做得对,Gradle将生成一个gradle clean idea 文件夹,您可以使用以下内容控制生成测试报告的位置:

/build

运行测试的一个优点是&#34;纯TestNG&#34;而不是使用Gradle执行程序,IntelliJ-IDEA将向您显示有关各个测试成功的更多信息。使用Gradle运行时,IntelliJ-IDEA不够智能,无法向您显示该信息,因此您需要依赖于测试报告。