puzzle / jenkins-pipeline-shared-libraries

Shared functionality for Jenkins Pipeline Groovy scripts.
GNU General Public License v3.0
10 stars 13 forks source link

Migrate to "Jenkins Pipeline Unit testing framework" #44

Closed ioboi closed 2 years ago

ioboi commented 2 years ago

This pull request is a demonstration if we decide to move from Spock to JenkinsPipelineUnit.

Note: Only migrated tests work at the moment.

This pull request is intended as a discussion basis.

chrira commented 2 years ago

Tests seem more object oriented -> good I miss the test method structure "given, when, then". Could be done with comments.

What are the benefits for changing the test framework? Are all tests easy to migrate?

ioboi commented 2 years ago

Hi @chrira

The only benefit I see at the moment is, that we migrate to another Unit-Test-Framework (JUnit) but this is also just a matter of taste I guess :smile:

As most tests at the moment only happen to check the call stack, we would have to write a lot of code.

For example before:

1 * getPipelineMock("error").call('missing parameter: hallo')

this becomes:

assertThat(helper.callStack.stream()
                 .filter({ it.methodName == "error" })
                .flatMap({ Arrays.stream(it.args) })
                .any({ it == "missing parameter: hallo" })).isTrue()

with AssertJ or with just JUnit:

assertTrue helper.callStack.stream()
                 .filter({ it.methodName == "error" })
                .flatMap({ Arrays.stream(it.args) })
                .any({ it == "missing parameter: hallo" })

As I understand Jenkins Pipeline Unit really shines when used to test pipelines using the shared library.