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.
In this rule, we check for the use of operators, such as, == and != in assertTrue or assertFalse methods and suggest replacing with either a assertSame or assertNotSame 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==b);// could be assertSame(a, b);assertTrue(a!=b);// could be assertNotSame(a, b);assertFalse(a==b);// could be assertNotSame(a, b);assertFalse(a!=b);// could be assertSame(a, b);}}