I'm having trouble debugging test methods (written in Java) that use JUnit 5 via JDB. More specifically, I can debug test methods with the annotation '@Test', but I can't with methods that use the annotations '@ParameterizedTest' and '@RepeatedTest'. When I try to debug with methods that use these annotations, JDB just doesn't stop during its execution, even adding breakpoints. I'll show an example to make it clearer:
Example with @Test annotation - works as expected
Code
TestClass.java (example class)public class TestClass
{
public long factorial(int x)
{
long response = 1;
for (int i=1; i<=x; i++) {
response *= i;
}
return response;
}
}
TestAnnotation.java (test method)
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class TestAnnotation
{
@Test
public void test1()
{
TestClass tc = new TestClass();
assertEquals(24, tc.factorial(4)); // Line 12
}
}
Input (cmd)
jdb -sourcepath ./ -classpath lib/junit-jupiter-api-5.6.2.jar;lib/junit-jupiter-params-5.6.2.jar;lib/apiguardian-api-1.1.0.jar;lib/junit-platform-console-standalone-1.6.2;./ org.junit.platform.console.ConsoleLauncher -cp lib -c TestAnnotation --disable-banner --details=none
> stop at TestAnnotation:12
> run
Output
run org.junit.platform.console.ConsoleLauncher -cp lib -c TestAnnotation --disable-banner --details=none
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint TestAnnotation:12
Breakpoint hit: "thread=main", TestAnnotation.test1(), line=12 bci=8
12 assertEquals(24, tc.factorial(4));
main[1] step into
>
Step completed: "thread=main", TestClass.factorial(), line=5 bci=0
5 long response = 1;
main[1]
...
Example with @ParameterizedTest annotation - does not work as expected
Code
ParameterizedTestAnnotation (test method)import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
public class ParameterizedTestAnnotation
{
@ParameterizedTest
@ValueSource(ints = {-1,0,1})
public void test1(int num)
{
TestClass tc = new TestClass();
assertEquals(1, tc.factorial(num)); // Line 14
}
}
Input (cmd)
jdb -sourcepath ./ -classpath lib/junit-jupiter-api-5.6.2.jar;lib/junit-jupiter-params-5.6.2.jar;lib/apiguardian-api-1.1.0.jar;lib/junit-platform-console-standalone-1.6.2;./ org.junit.platform.console.ConsoleLauncher -cp lib -c ParameterizedTestAnnotation --disable-banner --details=none
> stop at ParameterizedTestAnnotation:14
> run
Output
run org.junit.platform.console.ConsoleLauncher -cp lib -c ParameterizedTestAnnotation --disable-banner --details=none
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint ParameterizedTestAnnotation:14
The application exited
I am working on an application that needs to debug these methods through a shell (in this example, cmd), so it is necessary that debugging be done via command line, and not through an IDE, for example.
Note: The files I used in this example, along with the libraries used can be found here.