導入依賴
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions><scope>test</scope></dependency>
當然,正常的Springboot也要導入
問題:不要引入
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.5.0</version><scope>test</scope>
</dependency>
這樣會出現依賴沖突,刪除只保留Test
點擊生成
即可生成測試類
添加注解
在類上添加@@SpringBootTest注解
如果想打印內容需要再加上@Slf4j注解
在啟動類的時候,會調用BeforeEach
然后遍歷整個@Test
最后調用@AfterEach方法來收尾