Testng在IntelliJ中停止使用gradle

问题描述 投票:0回答:1

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

没有它总是失败的compfile时间检查gradle。如果从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构建。它之前也在使用gradle构建,但是从最近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
gradle testng build.gradle
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.