注:此博客不再更新,所有最新文章將發表在個人獨立博客limengting.site。分享技術,記錄生活,歡迎大家關注
maven項目目錄結構:注意測試文件要放在test目錄下
pom.xml配置加上:
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
TestJunit.java:
package sunnietest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestJunit {
public static void main(String[] args) {
System.out.println("aa");
}
@Test
public void testJunit(){
System.out.println("hello junit!");
}
@Before
public void testBefore(){
System.out.println("before!");
}
@After
public void testAfter(){
System.out.println("after!");
}
}
輸出結果: