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 Automated Test Coverage #366

Merged
merged 11 commits into from
Dec 21, 2024

Conversation

shinigami-777
Copy link
Contributor

This is part of JENKINS-69756.
Added test for NodeLabelBuildParameter class specifically covering the MacroEvaluationException case in the getAction method.

Test coverage before:
nblp1

Test coverage after:
nblp2

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

@shinigami-777 shinigami-777 requested a review from a team as a code owner December 18, 2024 11:37
@github-actions github-actions bot added dependencies Dependency related change tests Automated test addition or improvement labels Dec 18, 2024
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 effort to increase test coverage, but there is so much use of mock objects that it reduces the value of the test. Based on the token-macro source code, there should not be a need to use mock objects for the test.

Signed-off-by: shinigami-777 <[email protected]>
@shinigami-777
Copy link
Contributor Author

Thanks for the effort to increase test coverage, but there is so much use of mock objects that it reduces the value of the test. Based on the token-macro source code, there should not be a need to use mock objects for the test.

Yes I looked at the TokenMacro source code and found the string to cause the exception without mocking. Thanks a lot for suggesting.

shinigami-777 and others added 9 commits December 21, 2024 19:26
Simpler expression fails evaluation without embedded newlines
Running the build and asserting that it was successful provides a
workspace and tests a little more of the code than if we construct a
build ourselves.
The hamcrest matchers provide clearer error messages when an assertion
fails.  The clearer error message makes it easier to diagnose failures.

The earlier change to run the build and wait for it to complete
successfully also changed the details of the exception being thrown.
Assert that the expected exception message is found in the log.
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 very much! Your test implementation looks very good. I adapted it with some additions that I found while exploring the test from inside a debugger. Specific details of each change are embedded in the commit comments for each of the commits:

  • 49c5d38 - simplify the node label expression
  • 0ab1ada - use a non-deprecated StreamTaskListener constructor
  • 3ac804e - run the build and assert that it passes
  • e479792 - use hamcrest matchers for better failure messages

Hopefully you're OK with my changes. I plan to merge this as soon as the CI checks pass.

@MarkEWaite MarkEWaite enabled auto-merge (squash) December 21, 2024 16:58
@MarkEWaite MarkEWaite merged commit 990c04c into jenkinsci:master Dec 21, 2024
18 checks passed
@shinigami-777 shinigami-777 deleted the extend-test-coverage branch December 21, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Dependency related change tests Automated test addition or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants