在IDEA pom.xml文件中导入junit5需要的安装包
导入依赖包后,即可在方法中添加@Test注解
@Test
public void test(){
System.out.println("hhhh");
}
要注意使用junit5框架注解时,要导入正确的包,这点很重要,示例:
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class test {
@BeforeAll public static void initAll(){ System.out.println("init all test"); } @Test public void test1(){ System.out.println("test1"); } @Test public void test2(){ System.out.println("test2"); } @AfterAll public static void tearDownAll(){ System.out.println("tear down all test"); }
}
注意:在IDEA Terminal窗口输入mvn test后如果不执行测试用例,需要在pom.xml文件中加入以下配置:
Junit5 架构、新特性及基本使用(常用注解与套件执行):
https://mp.weixin.qq.com/s?__biz=MzU3NDM4ODEzMg==&mid=2247487640&idx=1&sn=6b2890d1cc5e3b5dd8cf52275a271ae3&chksm=fd327253ca45fb45abab7d0ea0d185a8685d38b9d4c817f35b11e541b05baf0c12934b25d9e7&scene=126&sessionid=1590031754&key=a4785556f9e9bd2bc5543877efab1357b9b4a49f7b8c8d719e47ca59ec1a04a2204b255b59d2aa7bd4420b7000e3a0ba4a0b750286c4a1d3e53f7ac9a883bbacab0ad9c1ae6a66dd23ea0c5d038a98fa&ascene=1&uin=MjYzMjQwOTE4MQ%3D%3D&devicetype=Windows+10+x64&version=62090070&lang=zh_CN&exportkey=AX3R4Q1TiMhW6up255o%2FyZw%3D&pass_ticket=PxATw6NNukrlc8vpWQk1XWnOB0qVLmt56vaMD9xHsNd1E2k2WCh0DSkesKMq63yl
junit5注解:
https://tonydeng.github.io/2017/10/10/junit-5-annotations/