-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Background
The triggerJenkinsJob method in CtrlplaneJobPoller currently has a test method (testTriggerJenkinsJobWithParameters) in CtrlplaneJobPollerTest.java, but the implementation is commented out. This method is critical for the plugin's core functionality and should be properly tested.
Current Limitations
The current test file has a commented-out example implementation that shows how the test could be written, but there are challenges with mocking static methods like Jenkins.get().
Requirements
To properly implement this test, the following dependencies will be needed:
- Mockito Core - Already included in the project for basic mocking
- PowerMock - Required for mocking static methods like
Jenkins.get()- PowerMock dependencies to add:
Implementation Steps
-
Add PowerMock dependencies to the project's
pom.xml -
Update the test class with PowerMock annotations:
-
Implement the test by uncommenting and completing the example:
Testing Best Practices
- Isolate the unit under test: Mock all external dependencies to isolate the unit under test
- Use appropriate runners and annotations: For PowerMock, use the correct runners and annotations to enable static method mocking
- Verify interactions: Ensure the correct methods are called with the expected parameters
- Test error handling: Include test cases for error scenarios (e.g., job not found, build scheduling fails)
- Keep tests independent: Make sure each test is independent and doesn't rely on state from other tests
Additional Test Cases to Consider
- Test behavior when Jenkins job is not found
- Test behavior when job is not a parameterized job
- Test behavior when scheduleBuild2 returns null
- Test error handling scenarios
References
Metadata
Metadata
Assignees
Labels
No labels