Gradle间歇性地没有运行TestNG测试

时间:2013-11-18 19:49:46

标签: java selenium jenkins gradle testng

我目前正在使用Gradle运行我的TestNG Java测试时遇到一些奇怪的行为。每次运行,似乎随机数量的测试甚至无法构建。它们没有出现在测试报告中,也没有出现在Jenkins控制台输出中。它们显示为从当前的SVN版本中检出,但从我看到的内容来看,甚至都没有构建。

奇怪的是,只有指定在Chrome中运行的测试才会发生这种情况。我正在测试的产品完全支持Chrome,并且只支持部分Firefox,因此构建文件中的“chrome”组会被排除。这不是以前发生的,但我唯一的更新是Selenium Webdriver和Chromedriver。

这是我的build.gradle文件:

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

repositories {
    mavenCentral()
}

dependencies {
    compile "org.seleniumhq.selenium:selenium-java:2.37.0"
    compile "org.testng:testng:5.14.10"
    testCompile('org.uncommons:reportng:1.1.2') {
        exclude group: 'org.testng'
    }
    testCompile "junit:junit:4.8.2"
    compile "com.jayway.restassured:rest-assured:1.8.1"
}

//initialize thread count variable for parallel testing and default to 1
def threadCount = System.getProperty("MAXTHREADS", "1")

tasks.withType(Test) {
    maxParallelForks = 1
    forkEvery = 1000
    ignoreFailures = false

    // Pass all system properties to the tests
    systemProperties = System.getProperties()

    // Makes the standard streams (err and out) visible at console when running tests
    testLogging.showStandardStreams = true

    exclude '**/tasks/'
    exclude '**/quarantine/'

    classpath += configurations.testCompile
}

task firefox(type: Test) {
    maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
    testLogging.events "started"
    testLogging {
        events "started", "passed", "skipped", "failed", "standardOut", "standardError"
        exceptionFormat "full" // default is "short"
    }
    useTestNG() {
        excludeGroups 'chrome'
        useDefaultListeners = false
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/firefox")
    testReportDir = file("${reporting.baseDir}/firefox")

    systemProperties.BROWSER = System.getProperty('BROWSER', 'firefox')

    exclude '**/selenium/'
    exclude '**/setupscripts/'
}

task chrome(type: Test) {
    maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
    testLogging.events "started"
    useTestNG() {
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/chrome")
    testReportDir = file("${reporting.baseDir}/chrome")

    systemProperties.BROWSER = System.getProperty('BROWSER', 'chrome')

    exclude '**/selenium/'
    exclude '**/setupscripts/'
}

task internetExplorer(type: Test) {
    useTestNG() {
        excludeGroups 'chrome'
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }
    testReportDir = file("${reporting.baseDir}/internetExplorer")
    testResultsDir = file("${buildDir}/test-results/internetExplorer")

    systemProperties.BROWSER = System.getProperty('BROWSER', 'internetExplorer')

    exclude '**/selenium/'
    exclude '**/setupscripts/'
}

task applylicense(type: Test) {
    useTestNG() {
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/applyLicense")
    testReportDir = file("${reporting.baseDir}/applyLicense")

    scanForTestClasses = false
    include '**/setupscripts/ApplyLicense.class'
}

task uatsetup(type: Test) {
    useTestNG() {
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/uatSetup")
    testReportDir = file("${reporting.baseDir}/uatSetup")

    scanForTestClasses = false
    include '**/setupscripts/UatSetup.class'
}

task restsetup(type: Test) {
    useTestNG() {
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/restSetup")
    testReportDir = file("${reporting.baseDir}/restSetup")

    scanForTestClasses = false
    include '**/setupscripts/RestSetup.class'
}

task soapsetup(type: Test) {
    useTestNG() {
        useDefaultListeners = false;
        listeners << 'org.uncommons.reportng.HTMLReporter'
        listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        listeners << 'com.xmatters.testng.Listener'
    }

    testResultsDir = file("${buildDir}/test-results/soapSetup")
    testReportDir = file("${reporting.baseDir}/soapSetup")

    scanForTestClasses = false
    include '**/setupscripts/SoapSetup.class'
}

task selenium(type: Test) {
    testResultsDir = file("${buildDir}/test-results/selenium")
    testReportDir = file("${reporting.baseDir}/selenium")

    include '**/selenium/'
    exclude '**/webdriver/'
    exclude '**/*$*', '**/Abstract*'
    exclude '**/messagepanel/'
    exclude '**/propertylibrary/'
}

javadoc() {
    title = "xMod Page Objects API"
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.7'
}

这些更新是否可能导致此问题?我假设没有,因为我不相信要么在测试实际开始构建之前被调用(应该在控制台输出中记录)。

注意:

  • MAXTHREADS是10(2个节点 - 以parallalel运行的测试)
  • 正在运行的任务是chrome(Type: Test)

任何想法或建议都会很棒。

谢谢, 达尔文

0 个答案:

没有答案