Concept for how to test the functionality of this shared library.
There are different test types used for testing at different levels.
- unit tests (JUnit 4)
- single component
- internal functions of the library
- unit tests (JenkinsPipelineUnit)
- exposed library functionality (vars directory and classes)
- integration tests (Jenkins Unit Test Harness)
- several components working together
- functionality using Jenkins dependencies only
- functionality using internal dependencies only
- end-to-end tests (on real jenkins)
- external services needed (K8S, Registries, ...)
- complex test setup
INFO: Usage of the spock test framework is deprecated.
Groovy functions and classes are tested with unit tests. Dependencies are mocked. They are located in test/groovy
Function unit testing is done with BasePipelineTest's from JenkinsPipelineUnit. The test files are named *Test.groovy
Eg. test/groovy/vars for scripts in vars
Whole scripts are tested with a pipeline file. Mostly green-path testing is enough. Edge cases are tested in spec classes. The test files are named *PipelineTest.groovy
Tests can be executed with ./gradlew clean test
- JenkinsPipelineUnit
- Documentation for the Jenkins test framework can be found here: https://github.com/ExpediaGroup/jenkins-spock
- Source: src/com/puzzleitc/jenkins/DockerHub.groovy