我在 netbeans 6.9.1 中有一个 maven 项目,其中有一个 junit 4.4 测试类。
在 netbeans 上下文菜单中,我可以“清理并构建”我的项目,在输出中我可以看到,我的测试类已被 surefire 找到并运行。
现在我从上下文菜单中选择“调试测试文件”,输出结果如下
--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @
--- maven-surefire-plugin:2.7.2:test (default-cli) @
测试测试
没有要运行的测试。
到目前为止我检查过的内容:
构建项目找到测试文件,但
仍然存在且正确 *.pom依赖中只有一个junit - 4.4
类文件本身看起来像
导入junit.framework.TestCase;
导入 org.junit.Test;
公共(public)类 SomeTest 扩展了 TestCase { @测试 public void testFoo() throws Exception {/---/}
调试的 netbeans 操作描述看起来像
执行目标:test-compile surefire:test
设置属性: jpda.listen=true maven.surefire.debug=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} jpda.stopclass=${packageClassName} failIfNoTests=false//这是我的补充,没有它仍然失败 forkMode=一次 test=${className}
项目 *.pom 文件中的任何地方都没有 surefire 插件部分
最佳答案
这不是真正的 netbeans 问题。
您已经定义了 JUnit 3 测试,但您正在尝试使用 JUnit 4 运行器来运行它们。 Surefire 使用以下规则来确定使用哪个运行者(来自 maven-surefire-plugin Junit )
if the JUnit version in the project >= 4.7 and the parallel attribute has ANY value
use junit47 provider
if JUnit >= 4.0 is present
use junit4 provider
else
use junit3.8.1
您的项目中有 junit 4.4,因此它使用的是 junit4。由于您只有 2 个测试类,因此最好的选择是将您的测试重新定义为 JUnit 4 测试。删除 extends TestCase,将 @Test/@Before/@After 注释添加到您的测试中,并完全删除 JUnit 3 内容。
有关执行迁移的更多信息,请参阅 Best way to automagically migrate tests from JUnit 3 to JUnit 4?
关于java - 使用 netbeans 6.9.1 调试 Maven 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8325761/