Remove autoscan ITs and add withoutSemantic tests - #5870
Conversation
cac9406 to
455da33
Compare
The autoscan ITs validated the Java analyzer works without bytecode by comparing results with/without compiled binaries using SonarQube Orchestrator. This coverage is being replaced by withoutSemantic() unit tests in each rule's check test, which is faster and more granular. - Delete its/autoscan/ directory (test classes, pom.xml, 261 diff JSON files) - Remove autoscan module from its/pom.xml - Remove autoscan CI job from build.yml and promote job dependency - Remove Autoscan Test documentation from README.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add test_without_semantic() methods to ~575 check test files. These tests verify each rule's behavior when running without bytecode/semantic analysis, replacing coverage previously provided by the autoscan integration tests. Tests that require semantic analysis use verifyNoIssues() to confirm the rule correctly produces no false positives without bytecode. This is a work in progress - some tests may still need adjustment: - verifyIssues() vs verifyNoIssues() may need to be corrected for some rules after running the full test suite - A few complex test files were skipped and may need manual handling Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add verifyAnalysisSucceeds() to CheckVerifier for checks that raise a different set of issues without semantic analysis. This runs the analysis without asserting on the specific issues, verifying the check doesn't crash without bytecode. - Fix 48 tests that used verifyNoIssues() but where the check still raises issues without semantics: use verifyAnalysisSucceeds() instead. - Add test_without_semantic() to MissingPackageInfoCheckTest, MockitoAnnotatedObjectsShouldBeInitializedCheckTest, and AbstractRegexCheckTest. - Fix double blank lines before test_without_semantic in ~315 files. - Fix import ordering in DefaultEncodingUsageCheckTest. All 2251 tests in java-checks pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
455da33 to
74e2ec2
Compare
… assertions - Remove stray merge conflict marker in DateEnumsCheckTest.java - Remove misleading setExpectNoIssues() call in verifyAnalysisSucceeds() since the method never inspects issues or expectations afterward - Change withoutSemantic() tests for semantic-dependent checks (AccessibilityChangeCheck, MathClampMethodsCheck, InstanceOfPatternMatchingCheck) from verifyIssues() to verifyAnalysisSucceeds(), since these checks produce different issue sets without type resolution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ All code review findings resolved.
…avaCheckVerifier Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
| .onFile(mainCodeSourcesPath("checks/regex/AbstractRegexCheckSample.java")) | ||
| .withCheck(new IssueOnAllRegexCheck()) | ||
| .withoutSemantic() | ||
| .verifyAnalysisSucceeds(); |
There was a problem hiding this comment.
We should either assert the number of false-positives, false-negatives, or have an emoji in the sample annotations to mark differences (🩹 , 💩 ...?)
…sues Replace verifyAnalysisSucceeds() with verifyIssues() in 52 test_without_semantic() methods by creating dedicated WithoutSemantic sample files with correct Noncompliant/FN markers for each check's behavior without semantic analysis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| package checks; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.PrintStream; | ||
| import java.io.PrintWriter; | ||
| import java.text.FieldPosition; | ||
| import java.text.MessageFormat; | ||
| import java.util.Calendar; | ||
| import java.util.Formatter; | ||
| import java.util.GregorianCalendar; | ||
| import java.util.Locale; | ||
| import java.util.Random; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.logging.log4j.LogManager; | ||
|
|
There was a problem hiding this comment.
💡 Quality: WithoutSemantic sample files duplicate semantic samples and will drift
This commit introduces ~575 new *WithoutSemantic.java sample files that are near-verbatim copies of their existing semantic counterparts (e.g. PrintfMisuseCheckSampleWithoutSemantic.java vs PrintfMisuseCheckSample.java, SQLInjectionWithoutSemantic.java vs the original sample), differing only in the // Noncompliant/// FN markers. Because the code bodies are duplicated, future edits to the original samples won't propagate, so the two sets can silently diverge and the withoutSemantic coverage can rot. Consider either generating these files from the originals, or at minimum documenting the coupling so maintainers keep them in sync; where feasible, reuse the same sample file with the semantic-vs-no-semantic difference expressed only through markers.
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 6 resolved / 7 findingsRemoves the autoscan integration test module and adds lightweight withoutSemantic unit tests across check files. Consider extracting shared sample code for the new withoutSemantic tests to prevent test sample drift. 💡 Quality: WithoutSemantic sample files duplicate semantic samples and will drift📄 java-checks-test-sources/default/src/main/java/checks/PrintfMisuseCheckSampleWithoutSemantic.java:1-15 📄 java-checks-test-sources/default/src/main/java/checks/SQLInjectionWithoutSemantic.java:1-15 This commit introduces ~575 new ✅ 6 resolved✅ Quality: Stray double blank line before test_without_semantic in many files
✅ Quality: Import of org.junit.jupiter.api.Test added out of order
✅ Edge Case: verifyIssues() + withoutSemantic() reuses semantic sample files
✅ Quality: verifyAnalysisSucceeds() sets expectNoIssues but never verifies
✅ Quality: withoutSemantic tests weakened from verifyNoIssues to no assertion
...and 1 more resolved from earlier reviews 🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |


Summary
its/autoscan/integration test module (test classes, pom.xml, 261 diff JSON files, CI job)test_without_semantic()unit tests to ~575 check test files to replace the autoscan coverageThe autoscan ITs validated that the Java analyzer works without bytecode by comparing results with/without compiled binaries using SonarQube Orchestrator. This is slow and heavyweight. The same coverage is achieved by adding
withoutSemantic()unit tests to each rule's check test, which is faster, more granular, and easier to maintain.Current state (WIP)
Done
its/autoscan/directory entirelyautoscanmodule fromits/pom.xml.github/workflows/build.ymland from promote job's needsREADME.mdtest_without_semantic()to ~575 check test filesmvn test-compile -pl java-checks)Remaining work
mvn test -pl java-checks) and fix remaining failuresverifyIssues()changed toverifyNoIssues()(or vice versa)test_without_semantic()to skipped complex tests:MissingPackageInfoCheckTest(usesonFiles()plural + caching)MockitoAnnotatedObjectsShouldBeInitializedCheckTest(usestestCodeSourcesPathInModule+ classpath)AbstractRegexCheckTest(uses local inner class as check)Test plan
mvn test -pl java-checkspassesmvn validate -pl its/autoscanfails (module removed)🤖 Generated with Claude Code