rspec/rules/S2391/java/rule.adoc

70 lines
2.3 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
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
----
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
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 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[]