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

Improve test coverage #371

Merged
merged 14 commits into from
Dec 26, 2024
Merged

Conversation

code-arnab
Copy link
Contributor

Testing done

Hello @MarkEWaite, added new test cases which improves the test coverage from 80% to 85%.
Thank You.

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
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@code-arnab code-arnab requested a review from a team as a code owner December 23, 2024 19:35
@github-actions github-actions bot added the tests Automated test addition or improvement label Dec 23, 2024
@code-arnab
Copy link
Contributor Author

@MarkEWaite I just noticed that the "equals" test for NextLabelCause has the class set to LabelParameterValue and the report says the coverage of equals is zero. I tried doing it but got some weird "Symmetry" problems.
{25A323AB-CB97-4331-BB57-06B39FA28152}

@MarkEWaite
Copy link
Contributor

@MarkEWaite I just noticed that the "equals" test for NextLabelCause has the class set to LabelParameterValue and the report says the coverage of equals is zero. I tried doing it but got some weird "Symmetry" problems. {25A323AB-CB97-4331-BB57-06B39FA28152}

Thanks very, very much for detecting my mistake in that file! You are absolutely right that the test of the equals contract in that file is testing the wrong class. I'll need to look further into it. Thanks again for catching that mistake!

@code-arnab
Copy link
Contributor Author

@MarkEWaite I just noticed that the "equals" test for NextLabelCause has the class set to LabelParameterValue and the report says the coverage of equals is zero. I tried doing it but got some weird "Symmetry" problems. {25A323AB-CB97-4331-BB57-06B39FA28152}

Thanks very, very much for detecting my mistake in that file! You are absolutely right that the test of the equals contract in that file is testing the wrong class. I'll need to look further into it. Thanks again for catching that mistake!

Yup, no worries. Great Work!
This one surely is a bit tricky.

Start the Jenkins controller only once for the entire test so that it
runs faster.  This is more important on Windows than on Linux, but is not
harmful because the tests configure their needed Jenkins configuration
at the start of each test.

Use nodeName as the isEligible argument rather than label string.
Label string did not match a node so would always return false.
Remove the label declaration since it is not needed for these tests.

Confirm that the Jenkins controller is eligible when it has executors
and is not eligible when it does not have executors.

Check more details of the descriptors.
@MarkEWaite
Copy link
Contributor

While reviewing your changes, I expanded the isEligible tests in d19126e . Let me know if any of those changes are an issue for you.

@code-arnab
Copy link
Contributor Author

While reviewing your changes, I expanded the isEligible tests in d19126e . Let me know if any of those changes are an issue for you.

No it looks great! If anything it has broaden my perspective of how good tests should be written and it also highlighted some nuances that I missed like wrong access modifiers and test cases.
Though I had questions regarding the node setup that which I'd like to ask as I analyze it further.
Thank You again for the changes!

Assert more values are set by the constructors

Use both deprecated constructors in a test and mark the test as deprecated
so that the compiler does not warn about the use of deprecated methods.

Test agent and controller doList and test a case that doList fails to
find the agent label.
The doListNodes checks now cover failure cases
The getNextLabels test needs JenkinsRule and an agent, so those are
added to the test.

The deprecated constructor tests now check more values that are assigned
during object construction.
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!

@code-arnab
Copy link
Contributor Author

Thanks!

Thank You for the review!

Unexpected that myValue is not returned by parameterValue.getValue().
Seems to be a bug in the NodeParameterDefinition implementation.
NodeParameterDefinition declares a private field 'label' that receives
the value instead of it being stored in LabelParameterValue.label but
does not override the LabelParameterValue implementation of getValue().

Expanded coverage by using different triggerIfResult values that change
the behavior of the constructor.

Prefer agents in local variables rather than slaves.
@MarkEWaite MarkEWaite merged commit d932128 into jenkinsci:master Dec 26, 2024
18 checks passed
@code-arnab code-arnab deleted the improve-test-coverage branch December 26, 2024 15:01
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