【问题标题】:JUnit 5 ConsoleLauncher doesn't workJUnit 5 ConsoleLauncher 不起作用
【发布时间】:2018-03-13 13:31:31
【问题描述】:

我有一个如下所示的 DisplayNameDemo.java 文件

DisplayNameDemo.java

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

@DisplayName("A special test case")
public class DisplayNameDemo {

    @Test
    @DisplayName("Custom test name containing spaces")
    void testWithDisplayNameContainingSpaces() {
    }

    @Test
    @DisplayName("╯°□°)╯")
    void testWithDisplayNameContainingSpecialCharacters() {
    }

    @Test
    @DisplayName("???? ")
    void testWithDisplayNameContainingEmoji() {
    }
}

然后我编译成.class文件使用

javac -cp .:junit-platform-console-standalone-1.0.0.jar DisplayNameDemo.java

这条命令执行成功,我得到了一个DisplayNameDemo.class文件。

之后,我运行了如下所示的命令

java -jar junit-platform-console-standalone-1.0.0.jar --select-class DisplayNameDemo.class

但它失败并说“org.junit.platform.commons.util.PreconditionViolationException:无法加载名称为:DisplayNameDemo.class 的类”

请帮帮我,非常感谢!

【问题讨论】:

    标签: java junit command-line junit5


    【解决方案1】:

    您必须使用带有--select-class 的完全限定类名。此外,它需要在类路径上。默认情况下,它只包含以TestTests 结尾的类,因此您必须使用--include-classname 来禁用或更改过滤器。

    java -jar junit-platform-console-standalone-1.1.0.jar \
         --classpath build/classes/java/test \
         --select-class example.DisplayNameDemo \
         --include-classname '.*'
    

    【讨论】:

    • 还有我没仔细看文档是我的错,已经说明了什么是“--include-classname”的工作,lol~
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    相关资源
    最近更新 更多