Skip to content

Implement full test for triggerJenkinsJob method #5

Description

@coderabbitai

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:

  1. Mockito Core - Already included in the project for basic mocking
  2. PowerMock - Required for mocking static methods like Jenkins.get()
    • PowerMock dependencies to add:

Implementation Steps

  1. Add PowerMock dependencies to the project's pom.xml

  2. Update the test class with PowerMock annotations:

  3. Implement the test by uncommenting and completing the example:

Testing Best Practices

  1. Isolate the unit under test: Mock all external dependencies to isolate the unit under test
  2. Use appropriate runners and annotations: For PowerMock, use the correct runners and annotations to enable static method mocking
  3. Verify interactions: Ensure the correct methods are called with the expected parameters
  4. Test error handling: Include test cases for error scenarios (e.g., job not found, build scheduling fails)
  5. Keep tests independent: Make sure each test is independent and doesn't rely on state from other tests

Additional Test Cases to Consider

  1. Test behavior when Jenkins job is not found
  2. Test behavior when job is not a parameterized job
  3. Test behavior when scheduleBuild2 returns null
  4. Test error handling scenarios

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions