-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for JobInclusionJobProperty class #423
Add test for JobInclusionJobProperty class #423
Conversation
Any feedback would be appreciated 👍🏻. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions need to be strengthened. Many changes could happen that would still satisfy the not null assertion.
|
||
@Test | ||
public void getDescriptor() { | ||
assertNotNull(property.getDescriptor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a deeper assertion than not null.
@Test | ||
public void getJobAction() { | ||
// Assuming getJobAction returns some action | ||
assertNotNull(property.getJobActions(project)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a deeper assertion than not null.
@Test | ||
public void getJobActions() { | ||
// Assuming getJobActions returns a list of actions | ||
assertNotNull(property.getJobActions(project)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a deeper assertion than not null.
@Test | ||
public void getRequiredMonitorService() { | ||
// Assuming getRequiredMonitorService returns some service | ||
assertNotNull(property.getRequiredMonitorService()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a deeper assertion than not null.
@Test | ||
public void getProjectActions() { | ||
// Assuming getProjectAction returns some project action | ||
assertNotNull(property.getProjectActions(project)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a deeper assertion than not null.
Right I will deepen the tests for extensive testing next thing in the morning. |
…perty for extensive tests - Introduce `addJobGroup` method to add job groups with display name and value. - Introduce `getJobGroups` method to retrieve the list of job groups.
…perty for extensive tests - Introduce `addJobGroup` method to add job groups with display name and value. - Introduce `getJobGroups` method to retrieve the list of job groups.
… into job-inclusion-job-property-test # Conflicts: # src/main/java/jenkins/advancedqueue/jobinclusion/strategy/PropertyBasedJobInclusionStrategy.java
- Introduce `addJobGroup` method to add job groups with display name and value. - Introduce `getJobGroups` method to retrieve the list of job groups.
- Introduce `addJobGroup` method to add job groups with display name and value. - Introduce `getJobGroups` method to retrieve the list of job groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do let me know about these changes I made, I added a constructor to add and get JobGroups to extensively test and deepen the assertions in PropertyBasedJobInclusionStrategy class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request. I spent several hours with it yesterday. I did not see the benefit of the changes to the production object. The tests that use those changes seem to only test the changes themselves, not any of the already existing functionality.
I've added several other comments as well.
Note that some of the comments propose changes that are incomplete. You'll need to complete the changes on a local copy from your integrated development environment, because they propose to rename a field of the test object. Rename a field is easier from an IDE.
public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
public TestName testName = new TestName(); | ||
|
||
private JobInclusionJobProperty property; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reduce the differences to the existing test class by changing this to jobProperty
in all its usages.
private JobInclusionJobProperty property; | |
private JobInclusionJobProperty jobProperty; |
jobProperty = new JobInclusionJobProperty(true, "TestJobGroup"); | ||
descriptor = new JobInclusionJobProperty.DescriptorImpl(); | ||
public void setUp() throws Exception { | ||
property = new JobInclusionJobProperty(true, "testGroup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reduce this difference to the existing test class, since changing the name of the property does not help the test and it makes the review of differences more difficult.
property = new JobInclusionJobProperty(true, "testGroup"); | |
jobProperty = new JobInclusionJobProperty(true, "TestJobGroup"); |
public void prebuild() { | ||
// Assuming prebuild performs some pre-build actions | ||
assertTrue(property.prebuild(build, listener)); | ||
|
||
// Additional assertions to verify the state after prebuild | ||
assertNotNull(build); | ||
assertNotNull(listener); | ||
assertEquals( | ||
"testFolder_" + testName.getMethodName(), build.getProject().getName()); | ||
} | ||
|
||
@Test | ||
public void perform() throws IOException, InterruptedException { | ||
// Assuming perform executes some actions | ||
assertTrue(property.perform(build, launcher, listener)); | ||
|
||
// Additional assertions to verify the state after perform | ||
assertNotNull(build); | ||
assertNotNull(launcher); | ||
assertNotNull(listener); | ||
assertEquals( | ||
"testFolder_" + testName.getMethodName(), build.getProject().getName()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are methods that are inherited from the parent object. I'd rather not have tests of those methods in this class. Leave that test to the parent object. That will also allow you to remove the declarations of launcher
and listener
that are only used in these two tests.
public void prebuild() { | |
// Assuming prebuild performs some pre-build actions | |
assertTrue(property.prebuild(build, listener)); | |
// Additional assertions to verify the state after prebuild | |
assertNotNull(build); | |
assertNotNull(listener); | |
assertEquals( | |
"testFolder_" + testName.getMethodName(), build.getProject().getName()); | |
} | |
@Test | |
public void perform() throws IOException, InterruptedException { | |
// Assuming perform executes some actions | |
assertTrue(property.perform(build, launcher, listener)); | |
// Additional assertions to verify the state after perform | |
assertNotNull(build); | |
assertNotNull(launcher); | |
assertNotNull(listener); | |
assertEquals( | |
"testFolder_" + testName.getMethodName(), build.getProject().getName()); | |
} |
} | ||
|
||
@Test | ||
public void getJobGroupNameTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't delete the existing tests (like getJobGroupNameTest
). Your pull request should add to the tests rather than replacing existing tests.
} | ||
|
||
@Test | ||
public void getDescriptorTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case of deleting a test. I don't see the benefit of deleting this test.
@Test | ||
public void getJobGroupsTest() { | ||
JobInclusionJobProperty.DescriptorImpl descriptor = new JobInclusionJobProperty.DescriptorImpl(); | ||
ListBoxModel jobGroups = descriptor.getJobGroups(); | ||
|
||
jobGroups.add("testJobGroup", "testGroup"); | ||
// Verify that the jobGroups is not null | ||
assertNotNull(jobGroups); | ||
|
||
// Verify that the jobGroups is not empty | ||
assertFalse(jobGroups.isEmpty()); | ||
|
||
// Verify the size of the jobGroups | ||
assertEquals("Expected number of job groups", 1, jobGroups.size()); | ||
|
||
// Verify the properties of the first job group | ||
ListBoxModel.Option firstOption = jobGroups.get(0); | ||
assertNotNull(firstOption); | ||
assertEquals("Expected display name", "testJobGroup", firstOption.name); | ||
assertEquals("Expected value", "testGroup", firstOption.value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems to be only testing the additions to the JobInclusionJobProperty object. As far as I can tell, those additions are not needed.
@Test | |
public void getJobGroupsTest() { | |
JobInclusionJobProperty.DescriptorImpl descriptor = new JobInclusionJobProperty.DescriptorImpl(); | |
ListBoxModel jobGroups = descriptor.getJobGroups(); | |
jobGroups.add("testJobGroup", "testGroup"); | |
// Verify that the jobGroups is not null | |
assertNotNull(jobGroups); | |
// Verify that the jobGroups is not empty | |
assertFalse(jobGroups.isEmpty()); | |
// Verify the size of the jobGroups | |
assertEquals("Expected number of job groups", 1, jobGroups.size()); | |
// Verify the properties of the first job group | |
ListBoxModel.Option firstOption = jobGroups.get(0); | |
assertNotNull(firstOption); | |
assertEquals("Expected display name", "testJobGroup", firstOption.name); | |
assertEquals("Expected value", "testGroup", firstOption.value); | |
} |
@@ -41,6 +41,7 @@ | |||
* @since 3.0 | |||
*/ | |||
public class PropertyBasedJobInclusionStrategy extends JobInclusionStrategy { | |||
private static ListBoxModel jobGroups = new ListBoxModel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this addition is not needed.
private static ListBoxModel jobGroups = new ListBoxModel(); |
|
||
public static void addJobGroup(String displayName, String value) { | ||
jobGroups.add(displayName, value); | ||
} | ||
|
||
public static ListBoxModel getJobGroups() { | ||
return jobGroups; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this addition is not needed.
public static void addJobGroup(String displayName, String value) { | |
jobGroups.add(displayName, value); | |
} | |
public static ListBoxModel getJobGroups() { | |
return jobGroups; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Hi @MarkEWaite , Thank you for taking the time to review my pull request and provide detailed feedback. I truly appreciate the effort, especially during the holidays. Thanks again for your guidance! |
Testing done
Add test for JobInclusionJobProperty class
Fixes JENKINS-69757
Submitter checklist