Testng перестал работать с Gradle в IntelliJ - PullRequest
0 голосов
/ 08 апреля 2019

Мой фреймворк внезапно перестал работать.Я интегрировал Gradle с Testng и использую его для запуска своих скриптов через testng.xml в Gradle

Нет, всегда происходит сбой при проверке времени компиляции в 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

> 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 дня это произошло.

Как сказал Йоле в комментариях ниже, я удалил testCompile и дал его как compile, для которого теперь нет ошибки компиляции, но это то, что яполучил-

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

1 Ответ

0 голосов
/ 09 апреля 2019

У вас есть testCompile зависимость от testng, поэтому она доступна только в источниках тестирования (src / test).Однако у вас есть некоторый код в производственных источниках (src / main), ссылающийся на testng, и он не компилируется, потому что зависимость там не видна.Вам нужно изменить testCompile на обычную compile зависимость.

...