简体   繁体   English

使用netbeans 6.9.1调试maven测试?

[英]Debugging maven tests with netbeans 6.9.1?

I have a maven project in netbeans 6.9.1, in there a junit 4.4 test class. 我在netbeans 6.9.1中有一个maven项目,在那里有一个junit 4.4测试类。

In netbeans context menu I can "clean and build" my project and in output I can see, that my test class was found and run by surefire. 在netbeans上下文菜单中,我可以“清理并构建”我的项目,在输出中我可以看到,我的测试类是通过surefire找到并运行的。

Now I choose from context menu "debug test file", in output it goes like 现在我从上下文菜单“调试测试文件”中选择,在输出中就好了

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ < project-name> --- Compiling 2 source files to < project-path>\\target\\test-classes --- 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 report directory: < project-path>\\target\\surefire-reports --- maven-surefire-plugin:2.7.2:test(default-cli)@ <project-name> --- Surefire报告目录:<project-path> \\ target \\ surefire-reports


TESTS 试验


There are no tests to run. 没有测试可以运行。

What I've checked so far: 到目前为止我检查了什么:

  • Build project finds test files, but nonetheless < testSourceDirectory> is there and correct 构建项目找到测试文件,但是<testSourceDirectory>是正确的

  • There is only one junit - 4.4 in *.pom dependencies 只有一个junit - 4.4 in * .pom依赖项

  • class file itself looks like 类文件本身看起来像

    import junit.framework.TestCase; import junit.framework.TestCase;

    import org.junit.Test; import org.junit.Test;

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

  • netbeans action description for debug looks like 调试的netbeans动作描述看起来像

    execute goal: test-compile surefire:test 执行目标:test-compile surefire:test

    set properties : jpda.listen=true maven.surefire.debug=-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} jpda.stopclass=${packageClassName} failIfNoTests=false // this is my addition, w/o it still failed forkMode=once test=${className} 设置属性:jpda.listen = true maven.surefire.debug = -Xdebug -Xrunjdwp:transport = dt_socket,server = n,address = $ {jpda.address} jpda.stopclass = $ {packageClassName} failIfNoTests = false //这是我的补充,没有它仍然失败forkMode =一次test = $ {className}

  • there is no surefire plugin section anywhere in project *.pom files 项目* .pom文件中的任何地方都没有surefire插件部分

This isn't really a netbeans question. 这不是一个netbeans问题。

You've defined JUnit 3 tests, but you're trying to run them with a JUnit 4 runner. 您已经定义了JUnit 3测试,但是您尝试使用JUnit 4运行器来运行它们。 Surefire uses the following rule to determine which runner to use (from maven-surefire-plugin Junit ) 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

You've got junit 4.4 in your project, so it's using junit4. 你的项目中有junit 4.4,所以它使用的是junit4。 Since you've only got 2 test classes, the best option is to redefine your tests to be JUnit 4 tests. 由于您只有2个测试类,因此最好的选择是将测试重新定义为JUnit 4测试。 Remove the extends TestCase, add @Test/@Before/@After annotations to your tests, and remove the JUnit 3 stuff altogether. 删除扩展的TestCase,在测试注释之后添加@ Test / @ Before / @,并完全删除JUnit 3的东西。

For more information on doing the migration, see Best way to automagically migrate tests from JUnit 3 to JUnit 4? 有关执行迁移的更多信息,请参阅将测试从JUnit 3自动迁移到JUnit 4的最佳方法?

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

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