-
New Feature
-
Resolution: Unresolved
-
Major
It would be desirable to have a standard mechanism for testing Pipeline scripts without running them on a production server. There are two competing suggestions:
Mock framework
Inspired by Job DSL (example).
We could set up a GroovyShell in which step functions and global variables were predefined as mocks (in a fashion similar to Powermock, but easier in Groovy given its dynamic nature), and stub out the expected return value / exception for each, with some standard predefinitions such as for currentBuild.
Ideally the shell would be CPS-transformed, with the program state serialized and then reloaded between every continuation (though this might involve a lot of code duplication with workflow-cps).
Should be easy to pass it through the Groovy sandbox (if requested), though the live Whitelist.all from Jenkins would be unavailable, so we would be limited to known static whitelists, the @Whitelisted annotation, and perhaps some custom additions.
Quick and flexible, but low fidelity to real behavior.
JenkinsRule-style
Use an embedded Jenkins server, as per JenkinsRule in jenkins-test-harness, and actually create a WorkflowJob with the specified definition. Can use for example mock-slave to create nodes.
Need to have a "dry-run" flag so that attempts to do things like deploy artifacts or send email do not really take action. This could perhaps be a general API in Jenkins core, as it would be useful also for test instances (shadows of production servers), acceptance-test-harness, etc.
Slower to run (seconds per test case rather than milliseconds), and trickier to set up, but much more realistic coverage. The tests for Pipeline (and Pipeline steps) themselves use this technique.
- relates to
-
JENKINS-40285 global libraries test harness
-
- Resolved
-
- links to
[JENKINS-33925] Test framework for Jenkinsfile
Description |
Original:
It would be desirable to have a standard mechanism for testing Pipeline scripts without running them on a production server. There are two competing suggestions: h3. Mock framework Inspired by Job DSL ([example|https://github.com/sheehan/job-dsl-gradle-example/blob/e240056da6691bf0a2fdc99e5aab33bc49e42b2f/src/test/groovy/com/dslexample/GrailsCiJobBuilderSpec.groovy#L34-L49]). We could set up a {{GroovyShell}} in which step functions and global variables were predefined as mocks (in a fashion similar to Powermock, but easier in Groovy given its dynamic nature), and stub out the expected return value / exception for each, with some standard predefinitions such as for {{currentBuild}}. Ideally the shell would be CPS-transformed, with the program state serialized and then reloaded between every continuation (though this might involve a lot of code duplication with {{workflow-cps}}). Should be easy to pass it through the Groovy sandbox (if requested), though the live {{Whitelist.all}} from Jenkins would be unavailable, so we would be limited to known static whitelists, the {{@Whitelisted}} annotation, and perhaps some custom additions. Quick and flexible, but low fidelity to real behavior. h3. {{JenkinsRule}}-style Use an embedded Jenkins server, as per {{JenkinsRule}} in {{jenkins-test-harness}}, and actually create a {{WorkflowJob}} with the specified definition. Can use for example {{mock-slave}} to create nodes. Need to have a "dry-run" flag so that attempts to do things like deploy artifacts or send email do not really take action. This could perhaps be a general API in Jenkins core, as it would be useful also for test instances (shadows of production servers), {{acceptance-test-harness}}, etc. Slower to run (seconds per test case rather than milliseconds), and trickier to set up, but much more realistic coverage. |
New:
It would be desirable to have a standard mechanism for testing Pipeline scripts without running them on a production server. There are two competing suggestions: h3. Mock framework Inspired by Job DSL ([example|https://github.com/sheehan/job-dsl-gradle-example/blob/e240056da6691bf0a2fdc99e5aab33bc49e42b2f/src/test/groovy/com/dslexample/GrailsCiJobBuilderSpec.groovy#L34-L49]). We could set up a {{GroovyShell}} in which step functions and global variables were predefined as mocks (in a fashion similar to Powermock, but easier in Groovy given its dynamic nature), and stub out the expected return value / exception for each, with some standard predefinitions such as for {{currentBuild}}. Ideally the shell would be CPS-transformed, with the program state serialized and then reloaded between every continuation (though this might involve a lot of code duplication with {{workflow-cps}}). Should be easy to pass it through the Groovy sandbox (if requested), though the live {{Whitelist.all}} from Jenkins would be unavailable, so we would be limited to known static whitelists, the {{@Whitelisted}} annotation, and perhaps some custom additions. Quick and flexible, but low fidelity to real behavior. h3. {{JenkinsRule}}-style Use an embedded Jenkins server, as per {{JenkinsRule}} in {{jenkins-test-harness}}, and actually create a {{WorkflowJob}} with the specified definition. Can use for example {{mock-slave}} to create nodes. Need to have a "dry-run" flag so that attempts to do things like deploy artifacts or send email do not really take action. This could perhaps be a general API in Jenkins core, as it would be useful also for test instances (shadows of production servers), {{acceptance-test-harness}}, etc. Slower to run (seconds per test case rather than milliseconds), and trickier to set up, but much more realistic coverage. The tests for Pipeline (and Pipeline steps) themselves use this technique. |
Labels | Original: testing | New: 3.0 testing |
Labels | Original: 3.0 testing | New: followup testing |
Epic Link | New: JENKINS-35396 [ 171189 ] |
Workflow | Original: JNJira [ 169936 ] | New: JNJira + In-Review [ 183698 ] |
Component/s | New: pipeline-general [ 21692 ] |
Component/s | Original: workflow-plugin [ 18820 ] |
Component/s | New: workflow-cps-plugin [ 21713 ] | |
Component/s | Original: pipeline [ 21692 ] |
Link |
New:
This issue relates to |
Remote Link | New: This issue links to "JenkinsPipelineUnit (Web Link)" [ 15606 ] |