java - 使用 netbeans 6.9.1 调试 Maven 测试?

标签 java netbeans maven-2 junit surefire

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

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

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

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ --- 编译 2 个源文件到 \target\test-classes

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


测试测试


没有要运行的测试。

到目前为止我检查过的内容:

  • 构建项目找到测试文件,但 仍然存在且正确

  • *.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/

相关文章:

java - 在 Ubuntu 16.04 中安装 cassandra 时出现 dpkg oracle Jdk 错误

java - 尝试将多个患者添加到 Netbeans 中的患者表中

maven-2 - 使用 Maven2 过滤添加当前日期

java - javafx 上的模态对话框意外挂起

java - Sonar Qube。为 Java 创建自定义规则

oracle - Netbeans 中的 SQLJ

java - 如何从菜单栏打开框架

java - 使用 maven 创建 zip 文件

c - Maven2 + 原生maven插件

java - 单击 JButton 时椭圆形不改变颜色 - Java Swing