首页 > 解决方案 > JUnit5 控制台启动器在提供的类路径中找不到任何测试

问题描述

我已经下载了 JUnit 5 控制台启动器的独立 jar,但我无法使其与我的代码一起使用。

给定 file/pkg 结构src/test/java/com/fteotini/dummy/SubjectTest.java和以下测试类:

package com.fteotini.dummy;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class SubjectTest {
    @Test
    void it_runs() {
        assertTrue(true);
    }
}

运行时

java -jar junit-platform-console-standalone-1.5.1.jar -cp ./target/test-classes/com/fteotini/dummy --scan-classpath

它没有找到任何测试

Test run finished after 42 ms
[         2 containers found      ]
[         0 containers skipped    ]
[         2 containers started    ]
[         0 containers aborted    ]
[         2 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]

标签: javajunitjunit5

解决方案


类路径错误。在您的情况下,它应该如下所示:

-cp ./target/test-classes


推荐阅读