SpringBoot中如何利用Junit实现单元测试
导读:本文共749字符,通常情况下阅读需要2分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 1.需要在pom.xml中引入spring-boot-starter-test<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId></de... ...
目录
(为您整理了一些要点),点击可以直达。1.需要在pom.xml中引入spring-boot-starter-test
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId></dependency>
2.单元测试代码
两个关键的注解
@RunWith(SpringRunner.class)
@SpringBootTest
package com.niugang.test;import java.util.List;import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import com.niugang.entity.User;import com.niugang.service.UserService;
@RunWith(SpringRunner.class)
@SpringBootTestpublic class TestUser {
@Resource private UserService userService;
@Testpublic void test1(){List<User> list = userService.queryList(null);System.out.println("集合大小:"+list.size());}}
SpringBoot中如何利用Junit实现单元测试的详细内容,希望对您有所帮助,信息来源于网络。