SpringBoot集成JUnit測試功能,進(jìn)行查詢用戶接口測試。
實(shí)現(xiàn)步驟:
1.添加Junit起步依賴(默認(rèn)就有)
<!--spring boot測試依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- 編寫測試類:
- SpringRunner繼承SpringJUnit4ClassRunner秘案,使用哪一個Spring提供的測試引擎都可以夜郁。指定運(yùn)行測試的引擎
- @SpringBootTest的屬性值指的是引導(dǎo)類的字節(jié)碼對象
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
@Autowired
private UserMapper userMapper;
@Test
public void test() {
List<User> users = userMapper.queryUserList();
System.out.println(users);
}
}
-
控制臺打印信息
在這里插入圖片描述