使用NetBeans 6.9.1调试Maven测试?

4

我在NetBeans 6.9.1中有一个maven项目,在其中有一个junit 4.4测试类。

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

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

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ < project-name> --- Compiling 2 source files to < project-path>\target\test-classes

--- maven-surefire-plugin:2.7.2:test (default-cli) @ < project-name> --- Surefire report directory: < project-path>\target\surefire-reports


T E S T S


没有要运行的测试。

我已经检查了以下内容:

  • 构建项目发现测试文件,但< testSourceDirectory>仍然存在且正确

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

  • 类文件本身看起来像

    import junit.framework.TestCase;

    import org.junit.Test;

    public class SomeTest extends TestCase { @Test public void testFoo() throws Exception { /---/} }

  • NetBeans中的操作描述如下

    execute goal: 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}

  • 项目*.pom文件中没有surefire插件部分

1个回答

3

这并不是一个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?

感谢您的回答和文章。最终,我决定按照普通的Maven项目风格重新排列所有内容,删除了所有JUnit 3的东西,现在一切都正常工作了。 - Alexey Kuznetsov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接