在Mac中从命令行运行Junit的语法

时间:2019-07-24 13:07:10

标签: java macos junit command-line terminal

我想在Mac OS中从命令行运行Junit,但是我无法使用我创建的简单测试类来使其按预期运行。

我已经为此目的下载了junit-4.12.jar,并且正在用一种简单的测试方法编写一个非常简单的测试类。

我正在运行以下命令来编译该类:

javac -cp .:/Full/path/to/junit/junit-4.12.jar DemoTest.java 

..并运行以下命令以执行编译的类:

java -cp .:/Full/path/to/junit/junit-4.12.jar org.junit.runner.JUnitCore DemoTest 

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class DemoTest {

    @Test
    public void evaluate(){
         assertEquals(true, 1<2);
    }
}

当我从命令行运行junit类时,我期望看到“测试通过”,因为那是它应该生成的。相反,我收到以下错误消息(请注意,为了简单起见,我仅粘贴错误的第一行):

  

线程“ main”中的异常java.lang.NoClassDefFoundError:org / hamcrest / SelfDescribing

这是否意味着Im仅缺少hamcrest.jar文件以能够按预期运行该应用程序?

请告诉我您是否需要完整的错误堆栈跟踪!

1 个答案:

答案 0 :(得分:0)

作为错误消息

  

线程“主”中的异常java.lang.NoClassDefFoundError:   org / hamcrest / SelfDescribing

提到您错过了类路径中的<section class="features-box-style"> <div class="box"> <div class="image"> <img src="http://placekitten.com/1000/500" alt="" /> </div> <div class="content"> <div class="content-wrapper"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer</p> </div> </div> </div>库。下载并将其添加到类路径

hamcrest-core