rspec/rules/S2699/java/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

88 lines
2.5 KiB
Plaintext
Raw Permalink 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?
A test case without assertions ensures only that no exceptions are thrown. Beyond basic runnability, it ensures nothing about the behavior of the code under test.
This rule raises an exception when no assertions from any of the following known frameworks are found in a test:
* AssertJ
* Awaitility
* EasyMock
* Eclipse Vert.x
* Fest 1.x and 2.x
* Hamcrest
* JMock
* JMockit
* JUnit
* Mockito
* Rest-assured 2.x, 3.x and 4.x
* RxJava 1.x and 2.x
* Selenide
* Spring's ``++org.springframework.test.web.servlet.ResultActions.andExpect()++`` and ``++org.springframework.test.web.servlet.ResultActions.andExpectAll()++``
* Truth Framework
* WireMock
Furthermore, as new or custom assertion frameworks may be used, the rule can be parametrized to define specific methods that will also be considered as assertions. No issue will be raised when such methods are found in test cases. The parameter value should have the following format ``++<FullyQualifiedClassName>#<MethodName>++``, where ``++MethodName++`` can end with the wildcard character. For constructors, the pattern should be ``++<FullyQualifiedClassName>#<init>++``.
Example: ``++com.company.CompareToTester#compare*,com.company.CustomAssert#customAssertMethod,com.company.CheckVerifier#<init>++``.
=== Noncompliant code example
[source,java]
----
@Test
public void testDoSomething() { // Noncompliant
MyClass myClass = new MyClass();
myClass.doSomething();
}
----
=== Compliant solution
Example when ``++com.company.CompareToTester#compare*++`` is used as parameter to the rule.
[source,java]
----
import com.company.CompareToTester;
@Test
public void testDoSomething() {
MyClass myClass = new MyClass();
assertNull(myClass.doSomething()); // JUnit assertion
assertThat(myClass.doSomething()).isNull(); // Fest assertion
}
@Test
public void testDoSomethingElse() {
MyClass myClass = new MyClass();
new CompareToTester().compareWith(myClass); // Compliant - custom assertion method defined as rule parameter
CompareToTester.compareStatic(myClass); // Compliant
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
=== Parameters
.customAssertionMethods
****
Comma-separated list of fully qualified method symbols that should be considered as assertion methods. The wildcard character can be used at the end of the method name.
****
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]