Skip to content
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

Merged

Conversation

yashpal2104
Copy link
Contributor

Testing done

Add test for JobInclusionJobProperty class

Fixes JENKINS-69757

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira

@yashpal2104 yashpal2104 requested a review from a team as a code owner December 28, 2024 12:30
@github-actions github-actions bot added the tests Automated test addition or improvement label Dec 28, 2024
@yashpal2104
Copy link
Contributor Author

Any feedback would be appreciated 👍🏻. Thanks

Copy link
Contributor

@MarkEWaite MarkEWaite left a 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());
Copy link
Contributor

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));
Copy link
Contributor

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));
Copy link
Contributor

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());
Copy link
Contributor

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));
Copy link
Contributor

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.

@yashpal2104
Copy link
Contributor Author

Right I will deepen the tests for extensive testing next thing in the morning.

MarkEWaite and others added 8 commits December 28, 2024 13:18
…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.
Copy link
Contributor Author

@yashpal2104 yashpal2104 left a 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

Copy link
Contributor

@MarkEWaite MarkEWaite left a 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;
Copy link
Contributor

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.

Suggested change
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");
Copy link
Contributor

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.

Suggested change
property = new JobInclusionJobProperty(true, "testGroup");
jobProperty = new JobInclusionJobProperty(true, "TestJobGroup");

Comment on lines 85 to 107
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());
}
Copy link
Contributor

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.

Suggested change
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() {
Copy link
Contributor

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() {
Copy link
Contributor

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.

Comment on lines 219 to 239
@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);
}
Copy link
Contributor

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.

Suggested change
@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();
Copy link
Contributor

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.

Suggested change
private static ListBoxModel jobGroups = new ListBoxModel();

Comment on lines 123 to 130

public static void addJobGroup(String displayName, String value) {
jobGroups.add(displayName, value);
}

public static ListBoxModel getJobGroups() {
return jobGroups;
}
Copy link
Contributor

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.

Suggested change
public static void addJobGroup(String displayName, String value) {
jobGroups.add(displayName, value);
}
public static ListBoxModel getJobGroups() {
return jobGroups;
}

@MarkEWaite MarkEWaite self-requested a review January 1, 2025 17:00
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MarkEWaite MarkEWaite enabled auto-merge (squash) January 1, 2025 17:00
@MarkEWaite MarkEWaite merged commit 5bad03a into jenkinsci:master Jan 1, 2025
17 of 18 checks passed
@yashpal2104
Copy link
Contributor Author

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!

@yashpal2104 yashpal2104 deleted the job-inclusion-job-property-test branch January 1, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Automated test addition or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants