目 录CONTENT

文章目录

Junit4和Junit5

不争
2024-01-02 / 0 评论 / 0 点赞 / 13 阅读 / 2114 字

org.junit.jupiter.api.Test和org.junit.Test

今天单元测试遇到一个问题,在引入org.junit.Test做单元测试时,IDEA左边的启动标志Run Test不显示。很郁闷...

最终解决是删除了导入的org.junit.Test重新导入org.junit.jupiter.api.Test后启动标志才出现的。

查阅了下资料,原理是:

spring boot 2.2之前使用的是 Junit4

spring boot 2.2之后使用的是 Junit5


Spring Boot 2.2 前后区别

Spring Boot 2.2 之前的测试类

package com.example.demo1;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)

@SpringBootTest

public class Demo1ApplicationTests {

@Test

public void contextLoads() {

}

}

Spring Boot 2.2 之后的测试类

package com.example.demo;

import org.junit.jupiter.api.Test;

import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest

class DemoApplicationTests {

@Test

void contextLoads() {

}

}

此外呢,还有pom文件也有区别:

Spring Boot 2.2 之后的 pom.xml

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

Spring Boot 2.2 之后的 pom.xml

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine


转自:https://www.jianshu.com/p/bdd22240fe4b
0

评论区