Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Test assertions can be made more concise through the utilization of a more specialized assertion method.
This rule checks for the use of equals in assertTrue or assertFalse methods and suggests replacing with either an assertEquals or assertNotEquals method.
This enhances the error message clarity and improves the overall readability of the assertion for other developers.
Non-Compliant Code Examples
importorg.junit.Test;import staticorg.junit.Assert.*;classFoo{Objecta,b;@TestvoidtestFoo(){assertTrue(a.equals(b));// could be assertEquals(a, b);assertTrue(!a.equals(b));// could be assertNotEquals(a, b);assertFalse(a.equals(b));// could be assertNotEquals(a, b);assertFalse(!a.equals(b));// could be assertEquals(a, b);}}