feat: add import-based test discovery for Java - #1268
Merged
Conversation
Add Strategy 4 to Java test discovery: import-based matching. When a test file imports a class containing the target function, consider it a potential test for that function. This fixes an issue where tests like TestQueryBlob (which imports and uses Buffer) were not being discovered as tests for Buffer methods because the class naming convention didn't match. Includes test cases that reproduce the real-world scenario from aerospike-client-java where test class names don't follow the standard naming pattern. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit adds thorough testing and fixes several bugs discovered by running test discovery against real-world examples from aerospike-client-java. Bugs fixed: 1. Import extraction for wildcard imports (import com.example.*) was incorrectly extracting "example" as a class name 2. Static imports (import static Utils.format) were extracting the method name instead of the class name 3. *Tests.java files (plural) were not being discovered as test files 4. ClassNameTests pattern wasn't handled in naming convention matching New test cases added: - TestImportExtraction: 7 tests for import statement parsing - Basic imports, multiple imports, wildcard imports - Static imports, static wildcard imports, deeply nested packages - Mixed import scenarios - TestMethodCallDetection: tests for method call detection in tests - TestClassNamingConventions: 3 tests for naming patterns - *Test, Test*, *Tests suffix/prefix patterns All tests verified against real aerospike-client-java test files: - TestQueryBlob correctly imports Buffer class - TestPutGet correctly imports Assert, Bin, Key, etc. - TestAsyncBatch correctly imports batch operation classes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The test_detect_fixture_project test expects the java_maven fixture directory to have a pom.xml file for Maven build tool detection. Add the missing pom.xml with JUnit 5 dependencies. Also add .gitignore exception to allow pom.xml files in test fixtures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestQueryBlob(which imports and usesBuffer) were not being discovered as tests forBuffermethodsProblem
When running codeflash on aerospike-client-java, test discovery failed to map tests to functions when:
TestQueryBlobinstead ofBufferTest)Buffer)The previous strategies only matched tests based on:
CalculatorTest→Calculator)Solution
Add Strategy 4: Import-based matching
Test plan
test_discover_by_import_when_class_name_doesnt_matchthat reproduces the aerospike-client-java scenariotest_discover_by_direct_method_callfor direct calls🤖 Generated with Claude Code