Skip to content

Firestore: Migrate unit tests to assertThrows() #3562

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

Merged
merged 4 commits into from
Mar 23, 2022

Conversation

dconeybe
Copy link
Contributor

Some Firestore unit tests were using the problematic @Test(expected = Exception.class) annotation to test for expected exceptions. This pattern, however, is problematic because it can easily hide test failures if some other part of the test were to throw the expected exception type (or any subclass thereof). Using assertThrows() is far less problematic because it only checks exceptions of a specific block of code, not the entire test case. This PR converts Firestore unit tests to use assertThrows(). Googlers can see go/lsc-assertthrows and go/assertthrows for more details.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 18, 2022

Coverage Report 1

Affected Products

  • firebase-firestore

    Overall coverage changed from 45.69% (e3ae02d) to 45.68% (69d06a0) by -0.01%.

    FilenameBase (e3ae02d)Merge (69d06a0)Diff
    DeleteMutation.java95.00%90.00%-5.00%
    SetMutation.java97.14%94.29%-2.86%

Test Logs

Notes

  • Commit (69d06a0) is created by Prow via merging PR base commit (e3ae02d) and head commit (d74ab41).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Ef3pfrg21y.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 18, 2022

@dconeybe
Copy link
Contributor Author

/test smoke-tests

1 similar comment
@dconeybe
Copy link
Contributor Author

/test smoke-tests

@dconeybe dconeybe requested a review from wu-hui March 18, 2022 18:44
@dconeybe dconeybe assigned wu-hui and unassigned dconeybe Mar 18, 2022
@dconeybe dconeybe requested review from schmidt-sebastian and removed request for wu-hui March 19, 2022 00:12
@dconeybe dconeybe requested review from wu-hui and removed request for schmidt-sebastian March 19, 2022 03:34
@dconeybe dconeybe merged commit cf374de into master Mar 23, 2022
@dconeybe dconeybe deleted the dconeybe/ExpectedExceptionEqualsTrueToAssertThrows branch March 23, 2022 17:43
@firebase firebase locked and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants