Describe the bug
The get_test_methods() method of the JavaAnalysis analyzer in the Python SDK gives an incorrect test method name of void when a comment is placed between the JUnit @Test annotation and a test method that is not marked public.
To Reproduce
Steps to reproduce the behavior:
- Run the below code:
from cldk import CLDK
src = """class ExampleTest {
@Test
// this valid comment breaks test method name detection; try removing it
void exampleTest() { }
}
"""
ja = CLDK(language="java").analysis(source_code=src)
tests = ja.get_test_methods()
print(tests)
Expected behavior
The output should be a dictionary along the lines of {'exampleTest': '...'}
Instead, the following is output: {'void': '...'}
Additional context
Doing either of the following allows the analyzer to properly detect the name:
- Adding a
public qualifier (e.g. edit line 5 to be public void exampleTest() { }
- Removing the comment (e.g. remove line 4)
This pattern can be seen in production code; for example, in this snippet from the Apache commons-lang project.