How would I produce JUnit test report for groovy tests, suitable for consumption by Jenkins/Hudson?

后端 未结 4 1283
误落风尘
误落风尘 2021-02-06 05:05

I\'ve written several XMLUnit tests (that fit in to the JUnit framework) in groovy and can execute them easily on the command line as per the groovy doco but I don\'t quite unde

4条回答
  •  不要未来只要你来
    2021-02-06 05:56

    After a little hackage I have taken Eric Wendelin's suggestion and gone with Gradle.

    To do this I have moved my groovy unit tests into the requisite directory structure src/test/groovy/, with the supporting resources (input and expected output XML files) going into the /src/test/resources/ directory.

    All required libraries have been configured in the build.gradle file, as described (in its entirety) here:

    apply plugin: 'groovy'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.+'
    
        groovy module('org.codehaus.groovy:groovy:1.8.2') {
            dependency('asm:asm:3.3.1')
            dependency('antlr:antlr:2.7.7')
            dependency('xmlunit:xmlunit:1.3')
            dependency('xalan:serializer:2.7.1')
            dependency('xalan:xalan:2.7.1')
            dependency('org.bluestemsoftware.open.maven.tparty:xerces-impl:2.9.0')
            dependency('xml-apis:xml-apis:2.0.2')
        }
    }
    
    test {
        jvmArgs '-Xms64m', '-Xmx512m', '-XX:MaxPermSize=128m'
    
        testLogging.showStandardStreams = true //not sure about this one, was in official user guide
    
        outputs.upToDateWhen { false } //makes it run every time even when Gradle thinks it is "Up-To-Date"
    }
    

    This applies the Groovy plugin, sets up to use maven to grab the specified dependencies and then adds some extra values to the built-in "test" task.

    One extra thing in there is the last line which makes Gradle run all of my tests every time and not just the ones it thinks are new/changed, this makes Jenkins play nicely.

    I also created a gradle.properties file to get through the corporate proxy/firewall etc:

    systemProp.http.proxyHost=10.xxx.xxx.xxx
    systemProp.http.proxyPort=8080
    systemProp.http.proxyUser=username
    systemProp.http.proxyPassword=passwd
    

    With this, I've created a 'free-style' project in Jenkins that polls our Mercurial repo periodically and whenever anyone commits an updated XSL to the repo all the tests will be run.

    One of my original goals was being able to produce the standard Jenkins/Hudson pass/fail graphics and the JUnit reports, which is a success: Pass/Fail with JUnit Reports.

    I hope this helps someone else with similar requirements.

提交回复
热议问题