Skip to content

Commit 9d66272

Browse files
java-team-github-botError Prone Team
authored and
Error Prone Team
committed
Correction to UseCorrectAssertInTests.
Contrary to the current text, blaze test actually does enable asserts, in both dbg and opt modes. I've verified this by running a JUnit test containing "assert false" with "blaze test -c opt" and "blaze test -c dbg". My tests use a java_library BUILD rule that includes all the *Test.java files, and a GenTestRules to create the actual test targets. PiperOrigin-RevId: 626049936
1 parent a6ab21a commit 9d66272

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

docs/bugpattern/UseCorrectAssertInTests.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
Java assert statements are not run unless targets explicitly opt in via runtime
2-
flags to the JVM invocation. Tests are typically not run with asserts enabled,
3-
meaning a test will continue to pass even if a bug is introduced since these
4-
statements were never executed. To avoid this, use one of the assertion
5-
libraries that are always enabled, such as JUnit's `org.junit.Assert` or
6-
Google's Truth library. These will also produce richer contextual failure
7-
diagnostics to aid and accelerate debugging.
1+
Java assert statements are not run unless explicitly enabled via runtime flags
2+
to the JVM invocation.
3+
4+
If asserts are not enabled, then a test using assert would continue to pass even
5+
if a bug is introduced since these statements will not be executed. To avoid
6+
this, use one of the assertion libraries that are always enabled, such as
7+
JUnit's `org.junit.Assert` or Google's Truth library. These will also produce
8+
richer contextual failure diagnostics to aid and accelerate debugging.
89

910
Don't do this:
1011

0 commit comments

Comments
 (0)