org.sonar.l10n.java.rules.squid.S2698.html Maven / Gradle / Ivy
Adding messages to JUnit assertions is an investment in your future productivity. Spend a few seconds writing them now, and you'll save a lot of time on the other end when either the tests fail and you need to quickly diagnose the problem, or when you need to maintain the tests and the assertion messages work as a sort of documentation.
Noncompliant Code Example
assertEquals(4, list.size()); // Noncompliant
assertThat(list.get(0)).isEqualTo("pear"); // Noncompliant
Compliant Solution
assertEquals("There should have been 4 Fruits in the list", 4, list.size());
assertThat(list.get(0)).as("check first element").overridingErrorMessage("The first element should be a pear, not a %s", list.get(0)).isEqualTo("pear");
© 2015 - 2025 Weber Informatics LLC | Privacy Policy