Remove autoscan ITs and add withoutSemantic tests - #5870
Conversation
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>
| @Test | ||
| void test_without_semantic() { | ||
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/AccessibilityChangeCheckSample.java")) | ||
| .withCheck(new AccessibilityChangeCheck()) | ||
| .withJavaVersion(15) | ||
| .withoutSemantic() | ||
| .verifyIssues(); | ||
| } |
There was a problem hiding this comment.
⚠️ Edge Case: verifyIssues() + withoutSemantic() reuses semantic sample files
Many new test_without_semantic() methods call verifyIssues() while pointing at the same sample file whose // Noncompliant comments were authored for a full semantic analysis (e.g. AccessibilityChangeCheckTest, MathClampMethodsCheckTest, InstanceOfPatternMatchingCheckTest). withoutSemantic() disables type resolution, so any check that relies on semantics will raise a different (usually smaller) issue set and verifyIssues() will fail because the raised issues no longer match the expected comments. This is the bulk of the acknowledged remaining work; for semantic-dependent rules the intent (verify the check doesn't crash without bytecode) is better expressed with verifyNoIssues(), and only syntax-only rules should keep verifyIssues(). Each affected test needs to be triaged individually.
Was this helpful? React with 👍 / 👎
|
|
||
|
|
There was a problem hiding this comment.
💡 Quality: Stray double blank line before test_without_semantic in many files
A large number of the modified test files introduce two consecutive blank lines between the previous method's closing brace and the new @test method (e.g. AccessibilityChangeCheckTest lines 53-54, BufferedReaderBoilerplateCheckTest, CommentsMustStartWithCorrectNumberOfSlashesCheckTest, ControlCharacterInLiteralCheckTest, DefaultEncodingUsageCheckTest, ImportDeclarationOrderCheckTest 254-255, ReadlnWithPromptCheckTest, StringIndexOfRangesCheckTest, etc.). This is a formatting inconsistency across ~575 files; collapse to a single blank line for consistency.
Use a single blank line between methods.:
.verifyIssues();
}
@Test
void test_without_semantic() {
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.sonar.java.checks.verifier.CheckVerifier; | ||
| import org.junit.jupiter.api.Test; |
There was a problem hiding this comment.
💡 Quality: Import of org.junit.jupiter.api.Test added out of order
In DefaultEncodingUsageCheckTest the new import org.junit.jupiter.api.Test; is appended after the org.sonar.java... imports instead of being grouped with the other org.junit.jupiter imports, breaking alphabetical import ordering (a convention this very project enforces via ImportDeclarationOrderCheck). Move the import up next to the other junit imports.
Group the junit Test import with the other junit imports in alphabetical order.:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.sonar.java.checks.verifier.CheckVerifier;
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
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