简体   繁体   English

从Windows命令行运行Junit Test时出错

[英]Error when running Junit Test from Windows Command Line

Back 3 months ago I asked a similar question: Error when running JUnit Tests from DOS Command line 3个月前,我问过类似的问题: 从DOS命令行运行JUnit测试时出错

I haven't solved the problem yet so I simplified the process by trying to run a simple sample TestCase Class from my Windows DOS command line. 我还没有解决问题,所以我尝试通过Windows DOS命令行运行一个简单的示例TestCase类,从而简化了过程。

My TestCase Class is: 我的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");
       }

}

I have a folder E:\\Jenkins\\Test\\ where my compiled .class file exists and jUnit jar insdie E:\\Jenkins\\Test\\lib\\ 我有一个文件夹E:\\ Jenkins \\ Test \\,其中存在已编译的.class文件,而jUnit jar是insdie E:\\ Jenkins \\ Test \\ lib \\

See attached screen shots: 查看所附的屏幕截图:

在此处输入图片说明

在此处输入图片说明

The command I am running to execute this from command line on a Windows Server MS DOS prompt is: 我正在运行以在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

The output: 输出:

JUnit version 4.10
Could not find class: Test.TestCaseA

Time: 0

OK (0 tests)

在此处输入图片说明

What am I missing? 我想念什么? Please help. 请帮忙。

This looks like a classpath issue. 这看起来像是类路径问题。 For a package Test with a class file X:\\foo\\Test\\TestCaseA.class the directory you should include in the classpath is X:\\foo 对于具有类文件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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM