Framework for unit testing Jenkins pipelines
This change removes the null
argument to addShMock
/addBatMock
for registering a default matcher. The new API takes only a Closure
, meaning that you can simply remove the null
argument. Adapting your code should look something like this:
-helper.addShMock(null) { println(“No call matched”) }
+helper.addShMock { println(“No call matched”) }
(Note: version v1.18 will be skipped due to some problems I had with the Gradle release plugin, since we've already published the tag and artifacts for v1.19. 😅)
addParam
(#594) @nre-abletonparams
, you'll now get an exception when trying to do this. This won't work on a real Jenkins server, and now it won't work in this framework either. To modify the params
map, you must use addParams
.mockShOutputs
has been renamed to mockShHandlers
(see below, #498).helper.addShMock
took a String
as the first argument for an exact command to match. This method now can take a Pattern
to match a regular expression, a String
for an exact match (the same behavior as before), or no argument to match anything.Some examples:
@Test
void testWhatever() {
helper.addShMock(~/echo\s(.*)/, 'mock-output', 0)
helper.addShMock('echo "hello, world"', 'mock-output', 0)
helper.addShMock('default-mock-output', 0)
}
MockScriptHandler
constructor (#541) @nre-ableton. This is related to https://github.com/jenkinsci/JenkinsPipelineUnit/pull/498 and would be a breaking API change, but https://github.com/jenkinsci/JenkinsPipelineUnit/pull/498 had not been part of a release yet.sh
mock was removed. Formerly, the sh
mock would return either abcd123\n
for git rev-parse HEAD
or \nbbb\nccc\n
in all other cases (and a similar output for bat
). If your tests relied on this behavior, you must now register proper output for sh
commands like so:@Test
void testGit() {
helper.addShMock("git rev-parse HEAD", "\nbbb\nccc\n", 0)
def result = script.sh(script: "git rev-parse HEAD", returnStdout: true)
assertEquals("\nbbb\nccc\n", result)
}
Please see the documentation for mocking sh
for more information.
PipelineTestHelper.mockScriptOutputs
field was renamed to PipelineTestHelper.mockShOutputs
, in order to accommodate the new PipelineTestHelper.mockBatOutputs
field. If your tests called helper.mockScriptOutputs
, you can simply rename these usages to helper.mockShOutputs
.=
character (#468) @Brennebat()
function (#484) @UlrichEckhardtFull Changelog: https://github.com/jenkinsci/JenkinsPipelineUnit/compare/v1.10...v1.12
(Sorry for the confusion with the versioning; something went wrong with v1.11 and although the tag was published, it seems the binaries were not. Hence, v1.11 has been skipped and those changes are included in v1.12).