spring boot進行Test測試

spring boot中集成了junit測試,無需自行安裝junit。

在pom.xml中新增spring中的junit,若之前新增過junit會進行預設會採用spring boot中的junit

org.springframework.bootspring-boot-starter-testtest

在測試類新增@SpringBootTest註解,測試方法新增@Test註解。

需要注意!!!!如果有新增junit,請務必選擇org.junit.jupiter.api.Test的包。否則無法spring裝載的bean

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class Test1 {
   @Test
   public void test(){
      System.out.println("test");
   }
}