繁体   English   中英

使用netbeans 6.9.1调试maven测试?

[英]Debugging maven tests with netbeans 6.9.1?

我在netbeans 6.9.1中有一个maven项目,在那里有一个junit 4.4测试类。

在netbeans上下文菜单中,我可以“清理并构建”我的项目,在输出中我可以看到,我的测试类是通过surefire找到并运行的。

现在我从上下文菜单“调试测试文件”中选择,在输出中就好了

--- maven-compiler-plugin:2.3.2:testCompile(default-testCompile)@ <project-name> ---将2个源文件编译为<project-path> \\ target \\ test-classes

--- maven-surefire-plugin:2.7.2:test(default-cli)@ <project-name> --- Surefire报告目录:<project-path> \\ target \\ surefire-reports


试验


没有测试可以运行。

到目前为止我检查了什么:

  • 构建项目找到测试文件,但是<testSourceDirectory>是正确的

  • 只有一个junit - 4.4 in * .pom依赖项

  • 类文件本身看起来像

    import junit.framework.TestCase;

    import org.junit.Test;

    公共类SomeTest扩展TestCase {@Test public void testFoo()抛出异常{/ --- /}}

  • 调试的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测试。 删除扩展的TestCase,在测试注释之后添加@ Test / @ Before / @,并完全删除JUnit 3的东西。

有关执行迁移的更多信息,请参阅将测试从JUnit 3自动迁移到JUnit 4的最佳方法?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM