# \[java:s5960\] FP! Test class not recognized

**URL:** <https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555>\
**Category:** Report False-positive / False-negative...\
**Tags:** sonarqube, java\
**Created:** [November 14, 2025, 10:50am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555 "2025-11-14T10:50:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfroehlich](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mfroehlich](https://community.sonarsource.com/u/mfroehlich)\
**Post date:** [November 14, 2025, 10:50am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/1 "2025-11-14T10:50:05Z")

</div>

Sonar Qube: Community Build v25.7.0.110598  
Lint: 11.20.0.84274  
Java: 25  
Eclipse: 2025-09

The Java rule s5960 raises an issue, if assertEquals() and that like are called, beause the code is not recognized as test code.

As per the rule description code is recognized as test, if the package contains the “test” token. In most cases this can be done, but sometimes not.

Code should also be identified as test case, if the Class is called something like “FooBarTest”.

Especially a method should be treated as a test, if it is annotated with one of the two @Test annotations from JUnit, which is the most certain hint.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [November 17, 2025, 3:17pm UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/2 "2025-11-17T15:17:55Z")

</div>

Hi,

> [@mfroehlich](#):
>
> As per the rule description code is recognized as test, if the package contains the “test”

I’m not seeing that in the [rule description](https://rules.sonarsource.com/java/RSPEC-5960/). In fact, analysis recognizes tests because they’re identified as such either manually via `sonar.tests` or automatically by the SonarScanner for Maven or SonarScanner for Gradle.

How are your `sonar.sources` and `sonar.tests` identified for analysis?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![mfroehlich](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mfroehlich](https://community.sonarsource.com/u/mfroehlich)\
**Post date:** [November 17, 2025, 4:18pm UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/3 "2025-11-17T16:18:09Z")

</div>

I need to wait for my colleague, who manages our Sonar server. But, what I can tell, is, that the last paragraph from the rule’s description days this:

> Note: this does not apply for `assert` from Java itself or if the source code package name is related to tests (contains: `test` or `assert` or `junit`).

I’m not sure, if test classes are identified as such other than that here.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [November 17, 2025, 5:07pm UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/4 "2025-11-17T17:07:01Z")

</div>

Hi,

Wow. That’s what I get for skimming. 😳

I think it’s probably the description rather than the detection that’s wrong here. But I’ll flag this for the language experts and let them decide.

Sorry about that.

&nbsp;  
😅  
Ann

---

<div class="post-metadata">

**Author:** ![mfroehlich](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mfroehlich](https://community.sonarsource.com/u/mfroehlich)\
**Post date:** [November 18, 2025, 7:37am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/6 "2025-11-18T07:37:45Z")

</div>

Is it possible, that there’s a difference for Qube and Lint? I’m pretty sure, the description is correct for Lint.

---

<div class="post-metadata">

**Author:** ![mfroehlich](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mfroehlich](https://community.sonarsource.com/u/mfroehlich)\
**Post date:** [November 18, 2025, 8:03am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/7 "2025-11-18T08:03:51Z")

</div>

I had the chance to ask our Sonar server guy. And the decision, whether to handle a test class as test is indeed done by scanner settings.

In Lint it is done as the description says.

So my question now is: Can this be changed, so that Lint recognizes tests as tests, if annotated with one of the @Test annotations. I’m not sure, if a “Test” in the class name wuold be a good idea for detection. This could also refer to some other test meaning.

---

<div class="post-metadata">

**Author:** ![Leonardo\_Pilastri](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/leonardo_pilastri/32/38853_2.png) [@Leonardo\_Pilastri](https://community.sonarsource.com/u/Leonardo_Pilastri)\
**Post date:** [November 25, 2025, 1:17pm UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/9 "2025-11-25T13:17:04Z")

</div>

Hello, thank you for the report.  
I agree that the rule could be slightly more sophisticated, and allow assertions inside annotated test methods.  
I created a [ticket](https://sonarsource.atlassian.net/browse/SONARJAVA-5879) for this.

---

<div class="post-metadata">

**Author:** ![EclipseWizard](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/eclipsewizard/32/68610_2.png) [@EclipseWizard](https://community.sonarsource.com/u/EclipseWizard)\
**Post date:** [November 25, 2025, 10:46pm UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/12 "2025-11-25T22:46:49Z")

</div>

Fear @mfroehlich,

Is the issue shown incorrectly in Eclipse?

The implementation in SonarQube for IDE (SonarLint) relies on the Information provided by Eclipse JDT whether or not a Source Directory (and therefore the Packages and classes) are marked as Test Code or not.

Would you be so Kind to provide the **.classpath** file? The IDE Plug-in May raise the issues incorrectly whenever the entry for the Test Code Directory does Not Contain the **Test** Attribute.

This might therefore be here Both an issue with the Rule and the IDE Plug-in Not getting the correct values for the actual analysis. This behaviour differs from the analysis against SonarQube Server or Cloud, as the IDE Plug-in creates **sonar.tests** etc. Automatically based on the IDE and project configuration.

Cheers 🥂

---

<div class="post-metadata">

**Author:** ![mfroehlich](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mfroehlich](https://community.sonarsource.com/u/mfroehlich)\
**Post date:** [November 26, 2025, 10:11am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/13 "2025-11-26T10:11:10Z")

</div>

Tbh, I didn’t even know, you could flag a source folder as containing tests. I did that now.

Unfortunately the rule still hits.

So, it’s still a good idea to improve the rule to honor @Test annotations. But it should also respect that test folder setting.

Thanks for the learning. 😉

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [December 5, 2025, 8:47am UTC](https://community.sonarsource.com/t/java-s5960-fp-test-class-not-recognized/152555/15 "2025-12-05T08:47:44Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
