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
|
|
|
|
|
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
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
private JenkinsStepRule jsr = 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))
|
2018-06-06 11:19:19 +02:00
|
|
|
.around(jsr)
|
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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults()
|
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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults(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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults(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-02-02 15:45:45 +02:00
|
|
|
'**/target/surefire-reports/*.xml', 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)
|
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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults(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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults(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 {
|
2018-06-06 11:19:19 +02:00
|
|
|
jsr.step.testsPublishResults(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)
|
|
|
|
}
|
2018-02-02 13:25:18 +02:00
|
|
|
}
|