根據(jù)Hello world 創(chuàng)建出來項目以后, 我們繼續(xù)來為項目增加單元測試功能.
安裝依賴
pom.xml中新增
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
編寫測試代碼
創(chuàng)建包目錄
mkdir -p src/test/java/com/example
-
創(chuàng)建文件
HelloWorldTest.java
package com.example;import org.junit.Assert; import org.junit.Test; /** * Created by zy on 2016/11/8. */ public class HelloWorldTest { @Test public void sayHelloTest(){ HelloWorld helloWorld = new HelloWorld(); String result = helloWorld.sayHello(); Assert.assertEquals("Hello world",result); } }
執(zhí)行測試
mvn test