1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/TestsPublishResultsTest.groovy

129 lines
5.6 KiB
Groovy
Raw Normal View History

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
import util.BasePiperTest
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
class TestsPublishResultsTest extends BasePiperTest {
2018-02-02 13:25:18 +02:00
Map publisherStepOptions
List archiveStepPatterns
private JenkinsStepRule jsr = new JenkinsStepRule(this)
2018-02-02 13:25:18 +02:00
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.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 {
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 {
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 {
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 {
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 {
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 {
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
}