2018-02-02 13:25:18 +02:00
|
|
|
import org.junit.Before
|
2018-02-02 15:45:45 +02:00
|
|
|
import org.junit.Ignore
|
2018-02-02 13:25:18 +02:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
2019-02-08 13:30:59 +02:00
|
|
|
import org.junit.rules.ExpectedException
|
2018-02-02 13:25:18 +02:00
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.JenkinsStepRule
|
2018-02-02 13:25:18 +02:00
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
import static org.junit.Assert.assertTrue
|
|
|
|
|
|
|
|
import util.Rules
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class TestsPublishResultsTest extends BasePiperTest {
|
2018-02-02 13:25:18 +02:00
|
|
|
Map publisherStepOptions
|
|
|
|
List archiveStepPatterns
|
|
|
|
|
2019-02-08 13:30:59 +02:00
|
|
|
private ExpectedException thrown = ExpectedException.none()
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2018-02-02 13:25:18 +02:00
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2018-08-31 10:22:43 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2019-02-08 13:30:59 +02:00
|
|
|
.around(thrown)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2018-02-02 13:25:18 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() {
|
|
|
|
publisherStepOptions = [:]
|
|
|
|
archiveStepPatterns = []
|
|
|
|
// prepare checkResultsPublish step
|
|
|
|
helper.registerAllowedMethod('junit', [Map.class], {
|
|
|
|
parameters -> publisherStepOptions['junit'] = parameters
|
|
|
|
})
|
|
|
|
helper.registerAllowedMethod('jacoco', [Map.class], {
|
|
|
|
parameters -> publisherStepOptions['jacoco'] = parameters
|
|
|
|
})
|
|
|
|
helper.registerAllowedMethod('cobertura', [Map.class], {
|
|
|
|
parameters -> publisherStepOptions['cobertura'] = parameters
|
|
|
|
})
|
2018-02-19 11:26:50 +02:00
|
|
|
helper.registerAllowedMethod('perfReport', [Map.class], {
|
|
|
|
parameters -> publisherStepOptions['jmeter'] = parameters
|
|
|
|
})
|
2018-02-02 13:25:18 +02:00
|
|
|
helper.registerAllowedMethod('archiveArtifacts', [Map.class], {
|
|
|
|
parameters -> archiveStepPatterns.push(parameters.artifacts)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-02-02 15:45:45 +02:00
|
|
|
void testPublishNothingWithDefaultSettings() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript)
|
2018-02-02 13:25:18 +02:00
|
|
|
|
|
|
|
// ensure nothing is published
|
2018-02-02 15:45:45 +02:00
|
|
|
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
|
|
|
assertTrue('PmdPublisher options not empty', publisherStepOptions.jacoco == null)
|
|
|
|
assertTrue('DryPublisher options not empty', publisherStepOptions.cobertura == null)
|
2018-02-19 11:26:50 +02:00
|
|
|
assertTrue('FindBugsPublisher options not empty', publisherStepOptions.jmeter == null)
|
2018-02-02 15:45:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishNothingWithAllDisabled() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript, junit: false, jacoco: false, cobertura: false, jmeter: false)
|
2018-02-02 15:45:45 +02:00
|
|
|
|
|
|
|
// ensure nothing is published
|
|
|
|
assertTrue('WarningsPublisher options not empty', publisherStepOptions.junit == null)
|
|
|
|
assertTrue('PmdPublisher options not empty', publisherStepOptions.jacoco == null)
|
|
|
|
assertTrue('DryPublisher options not empty', publisherStepOptions.cobertura == null)
|
2018-02-19 11:26:50 +02:00
|
|
|
assertTrue('FindBugsPublisher options not empty', publisherStepOptions.jmeter == null)
|
2018-02-02 13:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-02-09 00:48:49 +02:00
|
|
|
void testPublishUnitTestsWithDefaultSettings() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript, junit: true)
|
2018-02-02 13:25:18 +02:00
|
|
|
|
|
|
|
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
|
|
|
// ensure default patterns are set
|
|
|
|
assertEquals('JUnit default pattern not set correct',
|
2018-11-16 09:57:09 +02:00
|
|
|
'**/TEST-*.xml', publisherStepOptions.junit.testResults)
|
2018-02-02 15:45:45 +02:00
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue('JaCoCo options are not empty', publisherStepOptions.jacoco == null)
|
|
|
|
assertTrue('Cobertura options are not empty', publisherStepOptions.cobertura == null)
|
2018-02-19 11:26:50 +02:00
|
|
|
assertTrue('JMeter options are not empty', publisherStepOptions.jmeter == null)
|
2018-02-02 15:45:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishCoverageWithDefaultSettings() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript, jacoco: true, cobertura: true)
|
2018-02-02 15:45:45 +02:00
|
|
|
|
|
|
|
assertTrue('JaCoCo options are empty', publisherStepOptions.jacoco != null)
|
|
|
|
assertTrue('Cobertura options are empty', publisherStepOptions.cobertura != null)
|
2018-02-02 13:25:18 +02:00
|
|
|
assertEquals('JaCoCo default pattern not set correct',
|
2018-02-02 15:45:45 +02:00
|
|
|
'**/target/*.exec', publisherStepOptions.jacoco.execPattern)
|
2018-02-02 13:25:18 +02:00
|
|
|
assertEquals('Cobertura default pattern not set correct',
|
2018-02-02 15:45:45 +02:00
|
|
|
'**/target/coverage/cobertura-coverage.xml', publisherStepOptions.cobertura.coberturaReportFile)
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue('JUnit options are not empty', publisherStepOptions.junit == null)
|
2018-02-19 11:26:50 +02:00
|
|
|
assertTrue('JMeter options are not empty', publisherStepOptions.jmeter == null)
|
2018-02-02 15:45:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishJMeterWithDefaultSettings() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript, jmeter: true)
|
2018-02-02 15:45:45 +02:00
|
|
|
|
2018-02-19 11:26:50 +02:00
|
|
|
assertTrue('JMeter options are empty', publisherStepOptions.jmeter != null)
|
|
|
|
assertEquals('JMeter default pattern not set',
|
|
|
|
'**/*.jtl', publisherStepOptions.jmeter.sourceDataFiles)
|
2018-02-02 15:45:45 +02:00
|
|
|
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue('JUnit options are not empty', publisherStepOptions.junit == null)
|
|
|
|
assertTrue('JaCoCo options are not empty', publisherStepOptions.jacoco == null)
|
|
|
|
assertTrue('Cobertura options are not empty', publisherStepOptions.cobertura == null)
|
2018-02-02 13:25:18 +02:00
|
|
|
}
|
2018-02-19 11:26:50 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testPublishUnitTestsWithCustomSettings() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.testsPublishResults(script: nullScript, junit: [pattern: 'fancy/file/path', archive: true, active: true])
|
2018-02-19 11:26:50 +02:00
|
|
|
|
|
|
|
assertTrue('JUnit options are empty', publisherStepOptions.junit != null)
|
|
|
|
// ensure default patterns are set
|
|
|
|
assertEquals('JUnit pattern not set correct',
|
|
|
|
'fancy/file/path', publisherStepOptions.junit.testResults)
|
|
|
|
assertEquals('JUnit default pattern not set correct',
|
|
|
|
'fancy/file/path', publisherStepOptions.junit.testResults)
|
|
|
|
// ensure nothing else is published
|
|
|
|
assertTrue('JaCoCo options are not empty', publisherStepOptions.jacoco == null)
|
|
|
|
assertTrue('Cobertura options are not empty', publisherStepOptions.cobertura == null)
|
|
|
|
assertTrue('JMeter options are not empty', publisherStepOptions.jmeter == null)
|
|
|
|
}
|
2019-02-08 13:30:59 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testBuildResultStatus() throws Exception {
|
|
|
|
stepRule.step.testsPublishResults(script: nullScript)
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testBuildWithTestFailuresAndWithoutFailOnError() throws Exception {
|
|
|
|
nullScript.currentBuild.getRawBuild = {
|
|
|
|
return [getAction: { type ->
|
|
|
|
return [getFailCount: {
|
|
|
|
return 6
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
|
|
|
stepRule.step.testsPublishResults(script: nullScript)
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testBuildWithTestFailuresAndWithFailOnError() throws Exception {
|
|
|
|
nullScript.currentBuild.getRawBuild = {
|
|
|
|
return [getAction: { type ->
|
|
|
|
return [getFailCount: {
|
|
|
|
return 6
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
|
|
|
|
thrown.expect(hudson.AbortException)
|
|
|
|
thrown.expectMessage('[testsPublishResults] Some tests failed!')
|
|
|
|
|
|
|
|
stepRule.step.testsPublishResults(script: nullScript, failOnError: true)
|
|
|
|
}
|
2018-02-02 13:25:18 +02:00
|
|
|
}
|