Java JUnit5-新注释-使用JDB调试
调试使用via的测试方法(用Java编写)时遇到问题。更具体地说,我可以使用注释调试测试方法,但不能使用使用注释和注释的方法。当我尝试使用使用这些注释的方法进行调试时,JDB在执行过程中不会停止,甚至添加断点。我将举一个例子来说明这一点: 带有@Test注释的示例-按预期工作 代码 java(示例类)Java JUnit5-新注释-使用JDB调试,java,junit,jdb,Java,Junit,Jdb,调试使用via的测试方法(用Java编写)时遇到问题。更具体地说,我可以使用注释调试测试方法,但不能使用使用注释和注释的方法。当我尝试使用使用这些注释的方法进行调试时,JDB在执行过程中不会停止,甚至添加断点。我将举一个例子来说明这一点: 带有@Test注释的示例-按预期工作 代码 java(示例类) public class TestClass { public long factorial(int x) { long response = 1;
public class TestClass
{
public long factorial(int x)
{
long response = 1;
for (int i=1; i<=x; i++) {
response *= i;
}
return response;
}
}
输入(cmd)
输出
带有@ParameteredTest注释的示例-未按预期工作
代码
参数化试验说明(试验方法)
输入(cmd)
输出
我正在处理一个需要通过shell(在本例中为cmd)调试这些方法的应用程序,因此有必要通过命令行而不是通过命令行来完成调试。
注意:我在本例中使用的文件以及使用的库都可以找到
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
}
}
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
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]
...
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
}
}
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
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