Skip to content

Commit

Permalink
Merge pull request #134 from darxriggs/test-always-collect-test-results
Browse files Browse the repository at this point in the history
Add tests for "always collect test results"
  • Loading branch information
oleg-nenashev committed Jan 17, 2020
2 parents 8a566cf + 55bd877 commit e3fa17b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,30 @@ class BuildPluginStepTests extends BasePipelineTest {
def script = loadScript(scriptName)
script.call(tests: [skip: true])
printCallStack()
// then the junit step is disabled
// the junit step is disabled
assertFalse(helper.callStack.any { call ->
call.methodName == 'junit'
})
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_build_error() throws Exception {
def script = loadScript(scriptName)
binding.setProperty('infra', new Infra(buildError: true))
try {
script.call([:])
} catch (ignored) {
// intentionally left empty
}
printCallStack()
// it runs the junit step
assertTrue(helper.callStack.any { call ->
call.methodName == 'junit'
})
assertJobStatusFailure()
}

@Test
void test_buildPlugin_with_defaults_with_gradle() throws Exception {
def script = loadScript(scriptName)
Expand All @@ -241,6 +258,25 @@ class BuildPluginStepTests extends BasePipelineTest {
})
}

@Test
void test_buildPlugin_with_build_error_with_gradle() throws Exception {
def script = loadScript(scriptName)
binding.setProperty('infra', new Infra(buildError: true))
// when running in a non maven project
helper.registerAllowedMethod('fileExists', [String.class], { s -> return !s.equals('pom.xml') })
try {
script.call([:])
} catch (ignored) {
// intentionally left empty
}
printCallStack()
// it runs the junit step
assertTrue(helper.callStack.any { call ->
call.methodName == 'junit'
})
assertJobStatusFailure()
}

@Test
void test_buildPlugin_with_failfast_and_unstable() throws Exception {
def script = loadScript(scriptName)
Expand Down
19 changes: 18 additions & 1 deletion src/test/groovy/BuildPluginWithGradleStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,30 @@ class BuildPluginWithGradleStepTests extends BasePipelineTest {
def script = loadScript(scriptName)
script.call(tests: [skip: true])
printCallStack()
// then the junit step is disabled
// the junit step is disabled
assertFalse(helper.callStack.any { call ->
call.methodName == 'junit'
})
assertJobStatusSuccess()
}

@Test
void test_buildPluginWithGradle_with_build_error() throws Exception {
def script = loadScript(scriptName)
binding.setProperty('infra', new Infra(buildError: true))
try {
script.call([:])
} catch (ignored) {
// intentionally left empty
}
printCallStack()
// it runs the junit step
assertTrue(helper.callStack.any { call ->
call.methodName == 'junit'
})
assertJobStatusFailure()
}

@Test
void test_buildPluginWithGradle_with_failfast_and_unstable() throws Exception {
def script = loadScript(scriptName)
Expand Down
7 changes: 6 additions & 1 deletion src/test/groovy/mock/Infra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package mock
class Infra implements Serializable {

private boolean trusted
private boolean buildError

public void checkout(String repo = null) { }

Expand All @@ -23,7 +24,11 @@ class Infra implements Serializable {
}

public Object runWithJava(String command, String jdk = null, List<String> extraEnv = null, Boolean addToolEnv = null) {
return command
if (buildError) {
throw new RuntimeException('build error')
} else {
return command
}
}

public boolean isTrusted() {
Expand Down

0 comments on commit e3fa17b

Please sign in to comment.