Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for allowEmptyResults option in JUnit Plugin #734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
see [Migration](Migration#migrating-to-143)
* Deprecated some methods in `JobManagement` interface, see [Migration](Migration#migrating-to-143)
* Removed anything that has been deprecated in 1.36, see [Migration](Migration#migrating-to-136)
* Add support for `allowEmptyResults` option in [JUnit Plugin](https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin)
* 1.42 (January 05 2016)
* Added support for the [Dashboard View Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Dashboard+View)
([JENKINS-29146](https://issues.jenkins-ci.org/browse/JENKINS-29146))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ job('example-1') {
job('example-2') {
publishers {
archiveJunit('**/minitest-reports/*.xml') {
allowEmptyResults()
retainLongStdout()
testDataPublishers {
publishTestStabilityData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package javaposse.jobdsl.dsl.helpers.publisher

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.ContextHelper
import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.dsl.RequiresPlugin

class ArchiveJUnitContext implements Context {
class ArchiveJUnitContext extends AbstractContext {
final TestDataPublishersContext testDataPublishersContext
boolean allowEmptyResults = false
boolean retainLongStdout = false

ArchiveJUnitContext(JobManagement jobManagement) {
super(jobManagement)
testDataPublishersContext = new TestDataPublishersContext(jobManagement)
}

/**
* If set, does not fail the build on empty test results.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a @since GroovyDoc tag with the next version, e.g. @since 1.43.

*
* @since 1.43
*/
@RequiresPlugin(id = 'junit', minimumVersion = '1.10')
void allowEmptyResults(boolean allow = true) {
allowEmptyResults = allow
}

/**
* If set, retains any standard output or error from a test suite in the test results after the build completes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class PublisherContext extends AbstractExtensibleContext {
testResults(glob)
keepLongStdio(junitContext.retainLongStdout)
testDataPublishers(junitContext.testDataPublishersContext.testDataPublishers)
if (jobManagement.isMinimumPluginVersionInstalled('junit', '1.10')) {
allowEmptyResults(junitContext.allowEmptyResults)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ class PublisherContextSpec extends Specification {
}

def 'call junit archive with all args'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('junit', '1.10') >> true

when:
context.archiveJunit('include/*') {
allowEmptyResults()
retainLongStdout()
testDataPublishers {
allowClaimingOfFailedTests()
Expand All @@ -434,8 +438,9 @@ class PublisherContextSpec extends Specification {
then:
with(context.publisherNodes[0]) {
name() == 'hudson.tasks.junit.JUnitResultArchiver'
children().size() == 3
children().size() == 4
testResults[0].value() == 'include/*'
allowEmptyResults[0].value() == true
keepLongStdio[0].value() == true
testDataPublishers[0].children().size() == 4
testDataPublishers[0].'hudson.plugins.claim.ClaimTestDataPublisher'[0] != null
Expand All @@ -451,19 +456,37 @@ class PublisherContextSpec extends Specification {
}

def 'call junit archive with minimal args'() {
setup:
jobManagement.isMinimumPluginVersionInstalled('junit', '1.10') >> true

when:
context.archiveJunit('include/*')

then:
with(context.publisherNodes[0]) {
name() == 'hudson.tasks.junit.JUnitResultArchiver'
children().size() == 3
children().size() == 4
testResults[0].value() == 'include/*'
keepLongStdio[0].value() == false
allowEmptyResults[0].value() == false
testDataPublishers[0].children().size() == 0
}
}

def 'call junit archive with minimal args, plugin version older than 1.10'() {
when:
context.archiveJunit('include/*')

then:
with(context.publisherNodes[0]) {
name() == 'hudson.tasks.junit.JUnitResultArchiver'
children().size() == 3
testResults[0].value() == 'include/*'
keepLongStdio[0].value() == false
testDataPublishers[0].children().size() == 0
}
}

def 'call archiveXUnit with no args'() {
when:
context.archiveXUnit {
Expand Down