
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
62 lines
1.7 KiB
Plaintext
62 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Adding messages to JUnit, FEST and AssertJ 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
|
|
|
|
[source,java]
|
|
----
|
|
assertEquals(4, list.size()); // Noncompliant
|
|
|
|
try {
|
|
fail(); // Noncompliant
|
|
} catch (Exception e) {
|
|
assertThat(list.get(0)).isEqualTo("pear"); // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
assertEquals("There should have been 4 Fruits in the list", 4, list.size());
|
|
|
|
try {
|
|
fail("And exception is expected here");
|
|
} catch (Exception e) {
|
|
assertThat(list.get(0)).as("check first element").overridingErrorMessage("The first element should be a pear, not a %s", list.get(0)).isEqualTo("pear");
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add a message to this assertion.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 9 Apr 2015, 07:48:54 Nicolas Peru wrote:
|
|
\[~ann.campbell.2] I think we should we also cover FestAssertions in this rule (which we use a lot internally, like more (instead of?) Junit assertions).
|
|
|
|
=== on 9 Apr 2015, 13:03:39 Ann Campbell wrote:
|
|
how's that?
|
|
|
|
=== on 9 Apr 2015, 13:14:05 Nicolas Peru wrote:
|
|
Looks good.
|
|
|
|
=== on 26 May 2020, 15:44:14 Johann Beleites wrote:
|
|
This rule appears extremely noisy for AssertJ (and potentially Fest?) - consider twice before putting it into the default profile.
|
|
|
|
endif::env-github,rspecator-view[]
|