gpt4 book ai didi

java - Gradle 和 TestNG 的 Intellij 设置

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:45 25 4
gpt4 key购买 nike

我开始在 Intellij 中使用 selenium 和 TestNG(Java 基础语言)创建一组测试。我能够在 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'
}
}

终端输出:

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 以相同的方式工作?

最佳答案

让我引用我正在从事的另一个示例项目: https://github.com/virenv/ParallelReporter

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

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

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

gradle clean idea

如果您将测试输出发送到 /out,那么您可能正在以 TestNG 的身份运行测试,而不是从 Gradle 执行器运行测试。如果你做得正确,Gradle 将生成一个 /build 文件夹,你可以通过如下方式控制测试报告的生成位置:

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

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

关于java - Gradle 和 TestNG 的 Intellij 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30039144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com