1
類ParserTest
在包myproject.tests
和存儲在這個目錄結構:如果類在包中,如何從命令行運行JUnit測試?
.
└── myproject
└── tests
└── ParserTest.class
設置當前shell會話的CLASSPATH(不-cp
選項,保持到Java調用乾淨):
export CLASSPATH=.:/usr/local/lib/java/junit-4.12.jar:/usr/local/lib/java/hamcrest-core-1.3.jar
調用JUnit運行並通過測試類作爲參數:
java org.junit.runner.JUnitCore myproject/tests/ParserTest
這個錯誤被拋出:
...
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [myproject/tests/ParserTest]
...
我花了一些時間來弄清楚,因爲我沒有在StackExchange上找到任何東西(使用我的searchterms),我寫了這個Q/A來幫助那些面臨同樣問題並使用相同術語搜索解。 – Creaturo