【问题标题】:Testng stopped working with gradle in IntelliJTestng 停止在 IntelliJ 中使用 gradle
【发布时间】:2019-04-08 12:18:22
【问题描述】:

我的框架突然停止工作。我已将 gradle 与 Testng 集成,并用于通过 gradle 中的 testng.xml 运行我的脚本

不,它总是在 gradle 中的 compfile 时间检查上失败。如果从 IntelliJ 运行正常,它运行良好。

import java.util.concurrent.TimeUnit

plugins {
    id 'java'
}
/*apply plugin:'application'
mainClassName = "com.xxxxxxx.smsApi.qa.framework.mainRunner"*/

group 'api_automation'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}
/*
apply plugin: 'java'
apply plugin: 'war'
*/

/*// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'

// In this section you declare where to find the dependencies of your project
repositories {
    mavenCentral()
    maven {
        url 'http://mvnrepository.com/maven2'
    }
    maven {
        url 'http://download.java.net/maven/2'
    }
}

war {
    baseName = 'api_automation'
}*/
test {
    reports {
        junitXml.enabled = true
        html.enabled = false
        reports.junitXml.destination = file("test-output/reports/")
    }
    useTestNG()
            {
                useDefaultListeners = true
                options.suites("src/test/java/testApi_Test_Scripts/smsApiAutomationSuite.xml")
                options.listeners << 'com.kaleyra.smsApi.qa.framework.listener.CustomListener'
                //options.listeners << 'com.kaleyra.smsApi.qa.framework.listener.EmailListener'
                //options.listeners << 'org.uncommons.reportng.HTMLReporter'
                options.listeners << 'org.uncommons.reportng.JUnitXMLReporter'
                systemProperty 'org.uncommons.reportng.title', 'sms_api_automation_results'

            }
    testLogging.events "passed", "skipped", "failed"
    testLogging.showStandardStreams = true
    testLogging.exceptionFormat = "full"

/*    //Disable the default groovy html reports since ReportNG is being used
    reports.html.enabled = false
    reports.junitXml.enabled=true
    reports.junitXml.destination=file("output/")*/

    //Interceptors
    beforeTest { desc ->
        println "\n*** Starting execution of test ${desc.className}.${desc.name} ***"
    }
    afterTest { descriptor, result ->
        println "<<< Test ${descriptor.name} resulted in ${result.resultType} and took "+getElaspedTime(result.endTime - result.startTime)+" >>>\n"
    }

    //Modify the test logging
    testLogging {
        showStandardStreams = true
        exceptionFormat "full"
    }
}
sourceSets {
    main {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
    test {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
}
dependencies {

    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
    testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
    //An assertion library that is better than JUnit defaults
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    //Better reporting for testng.  It outputs a nice html report
    testCompile 'org.uncommons:reportng:1.1.4'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
    compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
    compile group: 'org.json', name: 'json', version: '20160810'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
    compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
    compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
    compile 'com.relevantcodes:extentreports:2.41.2'
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'

}
def getElaspedTime(def time) {

    if(time / 1000 < 1)
    {
        return String.format("0 min, %.3f sec", time/1000)
    }
    else
    {
        return String.format("%d min, %d sec",
                TimeUnit.MILLISECONDS.toMinutes(time),
                TimeUnit.MILLISECONDS.toSeconds(time) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))

        )
    }
}
test {
    ignoreFailures = true
}

不知道该怎么办。我 90% 的项目工作都依赖于这种自动化。

直到上周末还好。不知道为什么它突然停止了,因为我没有对其进行任何更改。

当我运行 gradle build 时

> Task :compileJava FAILED
C:\Users\sobhit.s\Documents\xxxxx\src\main\java\framework\collection\Groups.java:9: error: package org.testng does not exist
import org.testng.Assert;

        Assert.assertEquals(responseSample.getStatusCode(),200);
        ^
  symbol:   variable Assert
  location: class XMLSendSMS
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:21: error: method does not override or implement a method from a supertype
    @Override
    ^
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:24: error: cannot find symbol
        Reporter.log("<b>Executing TestCase - " + result.getMethod().getMethodName()+" --> "+result.getMethod().getDescription()+"</b><br>\n");
        ^
  symbol:   variable Reporter
  location: class CustomListener
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:33: error: method does not override or implement a method from a supertype
    @Override
    ^
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:43: error: method does not override or implement a method from a supertype
    @Override
    ^
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:54: error: method does not override or implement a method from a supertype
    @Override
    ^
C:\Users\sobhit.s\Documents\gradle-example\src\main\java\framework\listener\CustomListener.java:57: error: cannot find symbol
            if (!(result.getThrowable() instanceof SkipException)) {
                                                   ^
  symbol:   class SkipException
  location: class CustomListener
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors

我添加了 testng 但仍然失败。不知道为什么突然就开始了。如果我直接运行就可以了。但不适用于 gradle build。它以前也可以使用 gradle build 工作,但从最近 3 天开始就发生了。

正如 yole 在下面的评论中所说-我已经删除了 testCompile 并给出了编译,现在编译错误不存在,但这就是我得到的-

16:21:35 > Task :compileJava
16:21:35 Note: Some input files use unchecked or unsafe operations.
16:21:35 Note: Recompile with -Xlint:unchecked for details.
16:21:47 
16:21:47 > Task :processResources NO-SOURCE
16:21:47 > Task :classes
16:21:47 > Task :jar
16:21:47 > Task :assemble
16:21:48 > Task :compileTestJava FAILED
16:21:48 
16:21:48 FAILURE: Build failed with an exception.
16:21:48 
16:21:48 * What went wrong:
16:21:48 Execution failed for task ':compileTestJava'.
16:21:48 > Could not resolve all files for configuration ':testCompileClasspath'.
16:21:48    > Could not find testng-jdk15.jar (org.testng:testng:6.9.10).
16:21:48      Searched in the following locations:
16:21:48          https://repo.maven.apache.org/maven2/org/testng/testng/6.9.10/testng-6.9.10-jdk15.jar

【问题讨论】:

  • “编译时检查失败”是什么意思?请指定您运行的确切命令,如果它产生错误消息,请发布它。
  • @yole 我也更新了错误日志。请帮忙。

标签: gradle testng build.gradle


【解决方案1】:

你有一个 testCompile 依赖于 testng,所以它只在测试源 (src/test) 中可用。但是,您在生产源 (src/main) 中有一些引用 testng 的代码,它无法编译,因为那里不可见依赖项。您需要将 testCompile 更改为常规的 compile 依赖项。

【讨论】:

  • 正如你所说,删除了 testCompile,而不是上面给出的编译和编译错误,但这是我帖子中更新的新错误
猜你喜欢
  • 2014-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多