單元測試步驟
- 添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- 添加測試父類
指定啟動(dòng)類缰儿,端口隨機(jī)
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WksixApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WksixApplicationTests {
@Test
public void contextLoads() {
}
}
- 測試具體service,只要繼承上面的測試父類即可
public class ArticleServiceImplTest extends WksixApplicationTests {
@Autowired
ArticleService articleService;
@Test
public void test(){
articleService.testTransaction();
}
}
@Test 導(dǎo)入的是 org.junit.Test