test: Add unit tests for BuildUserRecipientProvider#1532
test: Add unit tests for BuildUserRecipientProvider#1532Vinamra-tech wants to merge 4 commits intojenkinsci:mainfrom
Conversation
BuildUserRecipientProvider had no test coverage. Add three tests covering: - User who triggered the build receives email (happy path) - No email sent when build was not triggered by a user (SCM/timer cause) - Only the triggering user receives email, not committers in the changeset This distinguishes BuildUserRecipientProvider behaviour from DevelopersRecipientProvider, as documented in the source.
|
Hlw @Vinamra-tech, I noticed that in testNoEmailWhenBuildNotTriggeredByUser, you're explicitly mocking getCause() to return null. Since MockUtilities.addRequestor() isn’t called here anyway, the mock might not be needed. Also, depending on how BuildUserRecipientProvider internally resolves the cause, this could give a false impression of what’s actually being tested. Could you double-check if this mock is necessary, or if just not calling addRequestor() would be enough? |
|
Just a small style note I noticed that some other test files in this package use @DisplayName annotations on test methods to make the test output more readable. Would you consider adding them here too? Something like this, @test It’s a minor thing, but it would help keep things consistent with the rest of the codebase. |
|
I noticed the tests currently only cover Result.FAILURE. It might be worth adding a test for Result.SUCCESS or Result.UNSTABLE as well, just to make sure the behavior is consistent regardless of the build result. Of course, happy to be wrong if BuildUserRecipientProvider is result-independent but having a test to explicitly verify that would be a nice addition. |
Thanks for the comment! I actually tested removing the getCause() mock to see if it's redundant turns out it is necessary for this specific test. I did some research into the codebase and actually found out that If we let BuildUserRecipientProvider call the real build.getCause(), it eventually reaches TransientActionFactory.factoriesFor(). Because we are using Mockito here rather than spinning up a full @JenkinsRule test environment, the extension cache isn't initialized, which causes the test to crash with an IllegalStateException: Expected 1 instance of jenkins.model.TransientActionFactory$Cache but got 0. |
Sure thing!! I've now added the same. |
Well yes I did verify it's result-independent and verifying it is actually a great idea.I've added a new testEmailSentRegardlessOfBuildResult test covering Result.SUCCESS to ensure the behavior stays consisten |
|
Thanks for addressing all three points so thoroughly |
Thank You so much for your kind words and best wishes to you too!! |
Keep building.. |
BuildUserRecipientProvider had no test coverage. Add three tests covering:
This distinguishes BuildUserRecipientProvider behaviour from
DevelopersRecipientProvider, as documented in the source.
Testing done
All three tests pass locally via:
mvn test -Dtest=BuildUserRecipientProviderTestOutput:
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
Submitter checklist