簡體   English   中英

從帶有依賴項的命令行運行 JUnit5

[英]Running JUnit5 from Command line with dependencies

我有一個包含以下文件的 Java 項目:
C:\我的項目\我的包\我的測試.class
C:\MyProject\lib\junit-platform-console-standalone-1.5.2.jar
C:\MyProject\lib\other-library.jar

MyTests 文件是使用 IDE 和 junit-platform-console-standalone-1.5.2.jar 和 other-library.jar 編譯的。 我用 IDE 驗證了測試編譯並成功運行,但我的問題是:
如何從命令行(Windows 命令提示符)運行 MyTests.class 中的所有測試,包括依賴於 other-library.jar 文件的測試?

從我試過的“MyProject”目錄:

java -jar lib/junit-platform-console-standalone-1.5.2.jar -cp .;libs --scan-class-path --disable-ansi-colors

這確實運行了一些測試方法,但是對於使用 other-library.jar 文件的任何測試方法都會拋出 ClassNotFoundException。 有誰知道我可能做錯了什么?

我知道如果我用 JUnit4 jar 文件編譯它,那么這個命令運行良好:

java -cp .;libs/* org.junit.runner.JUnitCore myPackage.MyTests

我本質上是在嘗試做同樣的事情,但使用的是 JUnit5。

鑒於布局
C:\我的項目\我的包\我的測試.class
C:\MyProject\lib\junit-platform-console-standalone-1.5.2.jar
C:\MyProject\lib\other-library.jar

這個命令應該有效。 jar 被明確列為 package 根目錄

C:\MyProject> java -jar lib/junit-platform-console-standalone-1.5.2.jar   \
                   --class-path=.;lib\other-library.jar                   \
                   --scan-class-path

或者,可以使用 -cp arguments 運行 java 命令,並直接調用 Junit main 方法。 這應該允許以通配符方式將所有 jars 加載到類路徑中。
奇怪的是 java -cp 不等同於 junit -cp 參數:

> java -cp ".;lib\*" org.junit.platform.console.ConsoleLauncher --scan-class-path

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM