rspec/rules/S2391/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

70 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
If the ``++suite++`` method in a JUnit 3 ``++TestCase++`` is not declared correctly, it will not be used. Such a method must be named "suite", have no arguments, be ``++public static++``, and must return either a ``++junit.framework.Test++`` or a ``++junit.framework.TestSuite++``.
Similarly, ``++setUp++`` and ``++tearDown++`` methods that aren't properly capitalized will also be ignored.
=== Noncompliant code example
[source,java]
----
Test suite() { ... } // Noncompliant; must be public static
public static boolean suite() { ... } // Noncompliant; wrong return type
public static Test suit() { ... } // Noncompliant; typo in method name
public static Test suite(int count) { ... } // Noncompliant; must be no-arg
public void setup() { ... } // Noncompliant; should be setUp
public void tearDwon() { ... } // Noncompliant; should be tearDown
----
=== Compliant solution
[source,java]
----
public static Test suite() { ... }
public void setUp() { ... }
public void tearDown() { ... }
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make this method "(public|static)".
This method should be named "[suite|setUp|tearDown]" not "[suit|xxx]".
This method should return either a "junit.framework.Test" or a "junit.framework.TestSuite".
'''
== Comments And Links
(visible only on this page)
=== is related to: S5826
=== on 27 Jan 2015, 20:11:49 Freddy Mallet wrote:
@Ann, perhaps this is a good time to introduce a new tag like "test" or "unit-test" and perhaps also "junit"
=== on 10 Jun 2020, 09:21:43 Quentin Jaquier wrote:
This rule targets an old version of JUnit (version 3, JUnit 4 has been released more than 10 years ago) and the current implementation behaves poorly in detecting potential ``++suite++`` methods, raising false positives, even on old code.
We do not feel that fixing the current implementation is worth the added value of this rule, we therefore decided to deprecate it.
In addition, we implemented RSPEC-5826 to target a similar problem in newer versions of JUnit.
=== on 16 Jul 2020, 15:23:46 Ann Campbell wrote:
\[~quentin.jaquier] you added labels to this rule yesterday. This morning the automation removed them because this rule is deprecated. FYI.
endif::env-github,rspecator-view[]