Junit 命令行测试 报错:Could not find class 理解及解决方法

一、报错 : 『Could not find class』

下面给出三个示例比较,其中只有第一个是正确的。

1. 
MyComputer:bin marikobayashi$ java -cp  .:./junit-4.10.jar org.junit.runner.JUnitCore NextdayTest 
JUnit version 4.10
...............
Time: 0.016

OK (15 tests)

2.
MyComputer:bin marikobayashi$ java -cp  .:./junit-4.10.jar org.junit.runner.JUnitCore ./NextdayTest 
JUnit version 4.10
Could not find class: ./NextdayTest

Time: 0.002

OK (0 tests)


3.
MyComputer:bin marikobayashi$ java -cp ./junit-4.10.jar org.junit.runner.JUnitCore ./NextdayTest 
JUnit version 4.10
Could not find class: ./NextdayTest

Time: 0.001

OK (0 tests)

二、 分析

java -cp .:./junit-4.10.jar org.junit.runner.JUnitCore NextdayTest

  1. -cp 指类路径 : "." 指的是当前路径,一定要有; 『:』 是分隔符, 『./junit-4.10.jar』 指当前路径下的./junit-4.10.jar包,也可以在其他路径下
  2. org.junit.runner.JUnitCore : 测试框架入口
  3. NextdayTest :待测Junit 测试用例+脚本 类。 PS : 前面不要加 路径,否则可能找不到(会被一并认为测试脚本类名)
原文地址:https://www.cnblogs.com/juking/p/6854950.html