【问题标题】:Error when running Junit Test from Windows Command Line从 Windows 命令行运行 Junit 测试时出错
【发布时间】:2014-07-24 17:53:08
【问题描述】:

3 个月前我问了一个类似的问题: Error when running JUnit Tests from DOS Command line

我还没有解决这个问题,所以我通过尝试从我的 Windows DOS 命令行运行一个简单的示例 TestCase 类来简化这个过程。

我的测试用例类是:

package Test;
import org.junit.Test;
import org.junit.After;
import org.junit.Before;
public class TestCaseA 
{
      @Before
       public void beforeMethod()
       {
           System.out.println("Before method..");
       }

       @Test
       public void JUnit4Test()
       {
          System.out.println("In test method");
       }

       @After
       public void afterMethod()
       {
          System.out.println("after method");
       }

}

我有一个文件夹 E:\Jenkins\Test\ 我编译的 .class 文件所在的文件夹和 jUnit jar insdie E:\Jenkins\Test\lib\

查看附加的屏幕截图:

我在 Windows Server MS DOS 提示符下从命令行执行此命令是:

1. I Change Directory into E:\Jenkins\Test
2. E:\Jenkins\Test>java -cp E:\Jenkins\Test\junit-4.10.jar;Test\TestCaseA.class; org.junit.runner.JUnitCore Test.TestCaseA

输出:

JUnit version 4.10
Could not find class: Test.TestCaseA

Time: 0

OK (0 tests)

我错过了什么?请帮忙。

【问题讨论】:

  • CP 有...;*E:\Jenkins\*Test\TestCaseA.class 是否有效? (星号突出显示)
  • E:\Jenkins\Test>java -cp E:\Jenkins\Test\lib\junit-4.10.jar;E:\Jenkins\Test\TestCaseA.class; org.junit.runner.JUnitCore Test.TestCaseA 我想这就是你的意思。不,这会引发相同的错误@AlexR
  • 好吧,最后的猜测。如果你 jar .class 文件并将 .jar 添加到 cp 会发生什么?
  • 这看起来像是一个类路径问题。对于带有类文件 X:\foo\Test\TestCaseA.class 的包 Test,您应该在类路径中包含的目录是 X:\foo
  • @McDowell - 是的,有效!您能否将其添加为答案,以便我给予您信任。

标签: java junit junit4


【解决方案1】:

这看起来像是一个类路径问题。对于带有类文件 X:\foo\Test\TestCaseA.class 的包 Test,您应该在类路径中包含的目录是 X:\foo

>java -cp E:\Jenkins\Test\lib\junit-4.10.jar;E:\Jenkins\ org.junit.runner.JUnitCore Test.TestCaseA

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-05-30
  • 2012-06-24
  • 1970-01-01
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 2016-11-03
  • 1970-01-01
相关资源
最近更新 更多