eclipse-jdt / eclipse-jdt/eclipse.jdt.core

ReportMethodCanBeStatic false positive on methods annotated with @Test

Open
#4,882 2 comments 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

JUnit requires @Test methods to be non-static
Expected Behavior

Methods annotated with @Test should not trigger ReportMethodCanBeStatic, or the rule should allow excluding test methods from this analysis.

Actual Behavior

Eclipse static analysis flags @Test methods as candidates for being static, causing CI failures.

```
@Test
public void testMetadataFilesGenerationAllFiles(@SystemOutGuard.SysOut Capturable systemOut)
throws Exception {
```

50. ERROR in /home/semaphore/checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/meta/MetadataGeneratorUtilTest.java (at line 63)00:49
public void testMetadataFilesGenerationAllFiles(@SystemOutGuard.SysOut Capturable systemOut)00:49
throws Exception {00:49
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^00:49
The method testMetadataFilesGenerationAllFiles(Capturable) from the type MetadataGeneratorUtilTest can be declared as static00:49

detected at: https://github.com/checkstyle/checkstyle/pull/18982

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.