rspec/rules/S2186/java/rule.adoc

46 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
JUnit assertions should not be made from the ``++run++`` method of a ``++Runnable++``, because failed assertions result in ``++AssertionError++``s being thrown. If the error is thrown from a thread other than the one that ran the test, the thread will exit but the test won't fail.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void run() {
// ...
Assert.assertEquals(expected, actual); // Noncompliant
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this assertion.
'''
== Comments And Links
(visible only on this page)
=== on 22 Oct 2014, 19:20:32 Ann Campbell wrote:
Note that Applicability is marked only for Tests
=== on 24 Nov 2014, 19:33:09 Nicolas Peru wrote:
I am guessing here and so the answer should probably part of the RSPEC : The run method is a run method of a Thread class ?
=== on 22 Apr 2015, 11:01:15 Ann Campbell wrote:
Since you're already implementing this [~nicolas.peru], I'm guessing it's okay.
=== on 22 Apr 2015, 11:20:20 Nicolas Peru wrote:
\[~ann.campbell.2]yes, more especially with the the mention of ``++Runnable++``
endif::env-github,rspecator-view[]