This issue reserved for Fidelity Open Source Workshop
We would like to increase our unit test coverage, to ensure our methods are returning sensible objects. In this case, we want to ensure BuildCDEvent::buildPipelineRunStartedModel returns a CloudEvent object, specifically one with a "type" field indicative of the Pipeline Run Started event, and the "pipelinename" extension accurately reflecting the getFullDisplayName() return value of Run getParent() result.
To limit the amount of mocking/stubbing, we recommend Mockito to create mocks for the Run / Job / TaskListener objects normally created by Jenkins. You may also used MockedStatic to mock static dependencies outside of the BuildCDEvent class (such as ModelBuilder).
To get started:
Create BuildCDEventTest.java in src/test/java/io/jenkins/plugins/cdevents
Add the Mockito extension to the test class with @ExtendWith(MockitoExtension.class)
Set up your mocks objects for the hudson.model.Run, hudson.model.Job and hudson.model.TaskListener objects we will be passing in to the method under test. (Tip: use Mockito's RETURNS_DEEP_STUBS feature)
In your test method, wrap the test in a try-with-resources block that sets up a MockedStatic instance of ModelBuilder. When ModelBuilder.buildJobModel(...) is called, you may return a new empty JobModel object.
Review the code for buildPipelineRunStartedModel in BuildCDEvent, and set the appropriate when(...).thenReturn(...) behavior needed for your test.
Call BuildCDEvent.buildPipelineRunStartedModel(...). Assert that .getType() and .getExtension("pipelinename") have the correct values.
This issue reserved for Fidelity Open Source Workshop
We would like to increase our unit test coverage, to ensure our methods are returning sensible objects. In this case, we want to ensure BuildCDEvent::buildPipelineRunStartedModel returns a CloudEvent object, specifically one with a "type" field indicative of the Pipeline Run Started event, and the "pipelinename" extension accurately reflecting the getFullDisplayName() return value of Run getParent() result.
To limit the amount of mocking/stubbing, we recommend Mockito to create mocks for the Run / Job / TaskListener objects normally created by Jenkins. You may also used MockedStatic to mock static dependencies outside of the BuildCDEvent class (such as ModelBuilder).
To get started:
BuildCDEventTest.java
insrc/test/java/io/jenkins/plugins/cdevents
@ExtendWith(MockitoExtension.class)
hudson.model.Run
,hudson.model.Job
andhudson.model.TaskListener
objects we will be passing in to the method under test. (Tip: use Mockito's RETURNS_DEEP_STUBS feature)