From 9d662726ccffcc9e9ec8746f0c2469f825a55ba2 Mon Sep 17 00:00:00 2001 From: Error Prone Team Date: Thu, 18 Apr 2024 08:56:45 -0700 Subject: [PATCH] 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 --- docs/bugpattern/UseCorrectAssertInTests.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/bugpattern/UseCorrectAssertInTests.md b/docs/bugpattern/UseCorrectAssertInTests.md index 4acece5fe6d..60c78e95ae2 100644 --- a/docs/bugpattern/UseCorrectAssertInTests.md +++ b/docs/bugpattern/UseCorrectAssertInTests.md @@ -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: