Skip to content

Commit

Permalink
Correction to UseCorrectAssertInTests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
java-team-github-bot authored and Error Prone Team committed Apr 18, 2024
1 parent a6ab21a commit 9d66272
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions docs/bugpattern/UseCorrectAssertInTests.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Java assert statements are not run unless targets explicitly opt in via runtime
flags to the JVM invocation. Tests are typically not run with asserts enabled,
meaning a test will continue to pass even if a bug is introduced since these
statements were never executed. To avoid this, use one of the assertion
libraries that are always enabled, such as JUnit's `org.junit.Assert` or
Google's Truth library. These will also produce richer contextual failure
diagnostics to aid and accelerate debugging.
Java assert statements are not run unless explicitly enabled via runtime flags
to the JVM invocation.

If asserts are not enabled, then a test using assert would continue to pass even
if a bug is introduced since these statements will not be executed. To avoid
this, use one of the assertion libraries that are always enabled, such as
JUnit's `org.junit.Assert` or Google's Truth library. These will also produce
richer contextual failure diagnostics to aid and accelerate debugging.

Don't do this:

Expand Down

0 comments on commit 9d66272

Please sign in to comment.