Java 用netbeans 6.9.1调试maven测试?
我在NetBeans6.9.1中有一个maven项目,其中有一个JUnit4.4测试类 在netbeans上下文菜单中,我可以“清理并构建”我的项目,在输出中,我可以看到我的测试类是由surefire找到并运行的 现在,我从上下文菜单中选择“调试测试文件”,在输出中,它如下所示 ---maven编译器插件:2.3.2:testCompile(默认testCompile)@<项目名称>--- 将2个源文件编译到Java 用netbeans 6.9.1调试maven测试?,java,netbeans,maven-2,junit,surefire,Java,Netbeans,Maven 2,Junit,Surefire,我在NetBeans6.9.1中有一个maven项目,其中有一个JUnit4.4测试类 在netbeans上下文菜单中,我可以“清理并构建”我的项目,在输出中,我可以看到我的测试类是由surefire找到并运行的 现在,我从上下文菜单中选择“调试测试文件”,在输出中,它如下所示 ---maven编译器插件:2.3.2:testCompile(默认testCompile)@--- 将2个源文件编译到\target\test类 ---maven surefire插件:2.7.2:test(默认cli
T T S T S
没有要运行的测试。 到目前为止我检查的内容:
- Build project找到测试文件,但
仍然存在并且正确 - 在*.pom依赖项中只有一个junit-4.4
- 类文件本身看起来像 导入junit.framework.TestCase 导入org.junit.Test 公共类SomeTest扩展了TestCase { @试验 public void testFoo()引发异常{/--/} }
- 调试的netbeans操作说明如下所示 执行目标:测试编译surefire:测试 设置属性: jpda.listen=true maven.surefire.debug=-Xdebug-Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} jpda.stopclass=${packageClassName} failIfNoTests=false//这是我添加的内容,但它仍然失败 forkMode=一次 test=${className}
- project*.pom文件中没有surefire插件部分
- 这不是一个真正的netbeans问题
您已经定义了JUnit3测试,但是您正在尝试使用JUnit4运行程序运行它们。Surefire使用以下规则确定要使用的运行程序(从)
您的项目中有junit4.4,因此它使用junit4。由于您只有2个测试类,最好的选择是将您的测试重新定义为JUnit4测试。删除extends TestCase,在测试中添加@Test/@Before/@After注释,并删除junit3内容
有关执行迁移的更多信息,请参阅感谢您的回答和文章。最后,我决定以正常的maven项目风格重新安排所有内容,删除所有JUnit3内容,现在一切正常。
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