TestSpark - a plugin for generating unit tests. TestSpark natively integrates different AI-based test generation tools and techniques in the IDE. Started by SERG TU Delft. Currently under implementation by JetBrains Research (Software Testing Research) for research purposes.
MIT License
47
stars
13
forks
source link
Incorrect construct under test selection after code type radio button click #251
Execution error due to specific construct under test selection.
In the following class, place a cursor on the first line (marked with *()**), press right click and select TestSpark for test generation; then select a line as a construct under test and proceed to generation. You will see an error stating that the no method was selected. This is because TestSparkAction.startUnitTestGenerationTool checks the 0th, 1st, and 2nd buttons, assuming that the 1st always corresponds to a method, although it is not true in this scenario (here, the 1st button corresponds to the line).
public class Calc { (*)
public int sum(int a, int b) {
return a + b; // line 3
}
public int multiply(int a, int b) {
return a * b;
}
}
To Reproduce
Steps to reproduce the behavior:
Use the example above (or any other class you have) and place the cursor on the very first line of the class definition.
Select test generation via TestSpark and select line 1 as a construct under test.
Start the generation
See error
Expected behavior
TestSpark should generate tests for a line in this scenario; the fix requires re-implementing the PsiHelper.getCurrentListOfCodeTypes method.
Additional contextSuggestion for the fix:
PsiHelper.getCurrentListOfCodeTypes returns Array<*>?, although the returned object is never null and always contains only String.
It is better to return List<CodeTypeOption> where CodeTypeOption = (org.jetbrains.research.testspark.data.CodeType, String). Next, store pairs of (org.jetbrains.research.testspark.data.CodeType, JRadioButton) within TestSparkAction.codeTypeButtons, so that we know what button corresponds to what code type without relying on indices of TestSparkAction.codeTypeButtons.
Describe the bug
Execution error due to specific construct under test selection.
In the following class, place a cursor on the first line (marked with *()**), press right click and select TestSpark for test generation; then select a line as a construct under test and proceed to generation. You will see an error stating that the no method was selected. This is because
TestSparkAction.startUnitTestGenerationTool
checks the 0th, 1st, and 2nd buttons, assuming that the 1st always corresponds to a method, although it is not true in this scenario (here, the 1st button corresponds to the line).To Reproduce Steps to reproduce the behavior:
line 1
as a construct under test.Expected behavior TestSpark should generate tests for a line in this scenario; the fix requires re-implementing the
PsiHelper.getCurrentListOfCodeTypes
method.Additional context Suggestion for the fix:
PsiHelper.getCurrentListOfCodeTypes
returnsArray<*>?
, although the returned object is never null and always contains onlyString
.It is better to return
List<CodeTypeOption>
whereCodeTypeOption = (org.jetbrains.research.testspark.data.CodeType, String)
. Next, store pairs of(org.jetbrains.research.testspark.data.CodeType, JRadioButton)
withinTestSparkAction.codeTypeButtons
, so that we know what button corresponds to what code type without relying on indices ofTestSparkAction.codeTypeButtons
.