简体   繁体   English

Gradle和TestNG的Intellij设置

[英]Intellij Settings for Gradle and TestNG

I started creating a set of tests with selenium and TestNG (Java base language) in Intellij. 我开始在Intellij中使用硒和TestNG(Java基本语言)创建一组测试。 I was able to compile and run within IntelliJ, but when I added a gradle file (shown below) I'm getting some compile path errors. 我能够在IntelliJ中进行编译和运行,但是当我添加gradle文件(如下所示)时,出现了一些编译路径错误。

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'
    }
}

Terminal Output: 终端输出:

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.

I'm guessing Intellij compiles things to the out folder, as I see that now, but no build folder. 我猜Intellij会将内容编译到out文件夹中,正如我现在看到的那样,但是没有build文件夹。 How do I change this to make gradle and Intellij work the same way? 如何更改此设置以使gradle和Intellij相同地工作?

Let me cite another example project I am working on: https://github.com/virenv/ParallelReporter 让我引用我正在处理的另一个示例项目: https : //github.com/virenv/ParallelReporter

At the top of my build.gradle, it is configured like so: 在我的build.gradle的顶部,它的配置如下:

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

Then setup your project with this command: 然后使用以下命令设置您的项目:

gradle clean idea

If you are getting test output to /out , then you are probably running the tests as TestNG, not from the Gradle executor. 如果要将测试输出输出到/ out ,则可能是作为TestNG运行测试,而不是从Gradle执行程序运行测试。 If you are doing it right, Gradle will generate a /build folder and you can control where your test report is generated with something like this: 如果操作正确,Gradle将生成一个/build文件夹,您可以使用以下方法控制生成测试报告的位置:

test {
    reports.html.destination = file("$buildDir/reports/gradle")
    ....

One advantage of running the tests as "pure TestNG" rather than using the Gradle executor, is that IntelliJ-IDEA will display to you more information about the individual test successes. 将测试作为“纯TestNG”而不是使用Gradle执行器运行的一个优点是,IntelliJ-IDEA将向您显示有关单个测试成功的更多信息。 When running with Gradle, IntelliJ-IDEA is not smart enough to show you that info and so you need to rely on your test report. 与Gradle一起运行时,IntelliJ-IDEA不够智能,无法向您显示该信息,因此您需要依靠测试报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM