一、报错 : 『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 : 前面不要加 路径,否则可能找不到(会被一并认为测试脚本类名)

相关文章:

  • 2022-12-23
  • 2021-06-03
  • 2021-11-12
  • 2021-08-19
  • 2022-02-10
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-04-27
  • 2021-08-07
  • 2021-12-14
  • 2022-01-20
  • 2022-12-23
  • 2021-07-30
  • 2021-04-08
相关资源
相似解决方案