【问题标题】:Junit 5 suite is not running tests in command lineJunit 5 套件未在命令行中运行测试
【发布时间】:2022-01-19 18:12:02
【问题描述】:

我正在尝试使用Junit 5 运行TestSuite。单个文件运行良好。但是TestSuite 在从命令行执行时没有运行。我正在使用junit-platform-console-standalone-1.6.0.jar 运行测试。

我的测试课程是:

package demo;
    
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
    
public class TestDemoClass1 {
    @Test
    public void test1() throws Exception {
        System.out.println("Test 1 from DemoClass 1");
    }
    
    @Test
    public void test2() throws Exception {
        System.out.println("Test2 from DemoClass 1");
    }
}

我的套件课程是:

package demo;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
    
@Suite
@SelectClasses({ TestDemoClass1.class })
public class TestSuite {

}

我用来从命令行运行的命令:

java -jar target/junit-platform-console-standalone-1.6.0.jar -cp .;target/test-classes/ -c demo.TestSuite  

【问题讨论】:

  • 这个命令的输出是:感谢使用JUnit!在junit.org 赞助支持其开发 测试运行在 67 毫秒后完成 [找到 2 个容器] [跳过 0 个容器] [启动了 2 个容器] [中止了 0 个容器] [成功了 2 个容器] [失败了 0 个容器] [找到了 0 个测试]
  • 套件在 1.8 版之前没有出现。所以独立 jar 1.6.0 和你用来编译的版本肯定不匹配。
  • 我尝试了相同版本的 jar,但结果仍然相同。不知道有什么问题,因为我没有使用错误或异常:java -jar target/junit-platform-console-standalone-1.8.2.jar -cp .;target/test-classes/ -c demo.TestSuite
  • 还有一件事:您必须将套件引擎的 jar 添加到类路径中。运行套件的不是 Jupiter,而是套件引擎。
  • 完成了@johanneslink。添加到 POM 并编译 .还是一样的结果没有运气

标签: junit5


【解决方案1】:

已解决“:https://github.com/junit-team/junit5/issues/2813. 问题不是在控制台启动器需要运行命令时添加 jar 集。 上面 GitHub 问题链接中的附加信息,但总的来说,您需要将以下 jar 添加到类路径: junit-平台-控制台-独立-1.8.2.jar;
junit-platform-suite-api-1.8.2.jar;
junit-platform-suite-commons-1.8.2.jar;
junit-platform-suite-engine-1.8.2.jar; \

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 2022-10-18
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2015-11-25
    • 2014-05-30
    • 2018-12-26
    • 2020-12-31
    相关资源
    最近更新 更多