SpringBoot Junit注意點

  1. 添加依賴 - 選對版本
    	<dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-test</artifactId>
    		<scope>test</scope>
    	</dependency>
    	<dependency>
    		<groupId>junit</groupId>
    		<artifactId>junit</artifactId>
    		<version>4.12</version>
    		<scope>test</scope>
    	</dependency>
    
  2. 添加註解
@RunWith(SpringRunner.class)
@SpringBootTest //(classes = application類.class) 

方法上添加註解

@Test
  1. test result 報錯 :Runner org.junit.internal.runners.ErrorReportingRunner
import org.junit.jupiter.api.Test;
替換爲
  import org.junit.Test;
  1. WEB項目需要加入註解
@WebAppConfiguration
  1. 引入配置文件
@TestPropertySource("classpath:appConfig.properties")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章