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
Infra: migrate to Truth in tests #9142
Comments
@pbludov would truth be used for check unit tests? If so, would we deprecate usage of |
That would be perfect. We should try to implement such extensions. |
@pbludov since this issue is approved, should we begin using truth in all new unit tests going forward? |
Yes, we try to keep this in mind during review |
Should we create separate issue to do #9142 (comment) so that we can use this in check UT's sooner? |
Also, would this be a good GSOC 2nd issue? Break this issue into one for each test class? |
Yes, but we need to find test classes that need update, as majority of tests already abstracted a lot from core asserts, example 7190c47 It would be good to think how we can enforce no new files with junit assert. |
What do you think - should we repeat code several times or extract method to make such things as one-liner?
this can be extracted in one method and be like What do you think? |
Questions to resolve the last of this issue:
|
https://truth.dev/api/latest/com/google/common/truth/Subject.html#isSameInstanceAs(java.lang.Object)
yes, we already do this. checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/utils/CommonUtilTest.java Lines 122 to 128 in 84eb861
|
The code you quoted uses If it is allowed to stay, then we will have to make an allowance for it as it is currently being forbidden.
|
#9142 (comment) |
https://stackoverflow.com/a/38866403 No good API, let's keep assertThrows |
We agreed to use Truth in tests. It is more readable and produces better diffs on failure.
This is how a regular unit test should be written:
Assertion starts with
assertWithMessage(...)
, followed bythat
and number of assertions.For asserting exceptions:
The text was updated successfully, but these errors were encountered: