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 tests for "always collect test results" #134

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
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