Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ruleKey": "S2699",
"hasTruePositives": true,
"falseNegatives": 157,
"falseNegatives": 158,
"falsePositives": 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The false negatives count went up by 1 (157 → 158) after adding approve to the pattern. This suggests the autoscan corpus contains at least one test method that calls something like approveOrder() or approvePayment() — a business-logic domain method that the rule now silently treats as an assertion, causing it to miss a genuine missing-assertion issue.

The word approve is broad enough to appear in non-assertion domain methods inside test code. Is this increase expected/acceptable as a deliberate trade-off, or is it a signal that the pattern should be narrowed (e.g. via a type-based check anchored to org.approvej, similar to how other frameworks are handled)?

  • Mark as noise

}
6 changes: 6 additions & 0 deletions java-checks-test-sources/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@
<artifactId>junit-platform-suite</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.approvej</groupId>
<artifactId>core</artifactId>
<version>1.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package checks.tests.AssertionsInTestsCheck;

import java.time.LocalDate;
import org.junit.jupiter.api.Test;

import static org.approvej.ApprovalBuilder.approve;
import static org.approvej.print.MultiLineStringPrintFormat.multiLineString;

class ApproveJTest {

@Test
void contains_no_assertions() { // Noncompliant
}

public String hello() {return "hello";}

@Test
void approve_string() {
String result = hello();
approve(result)
.byFile();
}

public record Person(String name, LocalDate birthDate) {}

@Test
void approve_person() {
Person jane = new Person("Jane Doe", LocalDate.of(1990, 1, 1));
approve(jane).named("jane").printedAs(multiLineString()).byFile();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class UnitTestUtils {

private static final String ORG_JUNIT_TEST = "org.junit.Test";
public static final Pattern ASSERTION_METHODS_PATTERN = Pattern.compile(
"(assert|verify|fail|should|check|expect|validate|andExpect).*" +
"(assert|verify|fail|should|check|expect|validate|andExpect|approve).*" +
// Eclipse Vert.x with JUnit 5 (VertxTestContext)
"|laxCheckpoint|succeedingThenComplete");
private static final Pattern TEST_METHODS_PATTERN = Pattern.compile("test.*|.*Test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void setup() {
"JMockit",
"Awaitility",
"AssertJ",
"ApproveJ",
"Custom"
})
void test(String framework) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ <h2>Why is this an issue?</h2>
code under test.</p>
<p>This rule raises an exception when no assertions from any of the following known frameworks are found in a test:</p>
<ul>
<li>ApproveJ</li>
<li>AssertJ</li>
<li>Awaitility</li>
<li>EasyMock</li>
Expand Down
Loading