A test method checks nothing: it calls no assertion, verification or helper of its class
What it finds
A test without an assertion passes as long as nothing throws, so it guards much less than its name suggests.
Reported is a test method, not expecting an exception through its annotation, whose body has no assert statement and calls nothing whose name starts with assert, verify, expect, check, should, fail, then, must or validate, and calls no method without a receiver, which may be a helper that asserts.
From the rule's source, test_without_assertion.rs.
import org.junit.jupiter.api.Test; class EmptyTest { @Test void runs() {tx0 reports: checks nothing new StringBuilder().append("x"); } @Test void checks() { assertTrue(true); } @Test void helps() { check(1); } @Test(expected = IllegalStateException.class) void throwsIt() { new StringBuilder(); } void assertTrue(boolean b) {} void check(int x) {}} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:test-checks-nothing" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:test-checks-nothing] reason="..."tx0 explain tx0/java:test-checks-nothing shows the same in the terminal. Found a false positive? Report it.