您好,登錄后才能下訂單哦!
這篇“SpringBoot中如何利用Junit實(shí)現(xiàn)單元測(cè)試”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“SpringBoot中如何利用Junit實(shí)現(xiàn)單元測(cè)試”文章吧。
1.需要在pom.xml中引入spring-boot-starter-test
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId></dependency>
2.單元測(cè)試代碼
兩個(gè)關(guān)鍵的注解
@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一種全新的編程規(guī)范,其設(shè)計(jì)目的是用來(lái)簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開發(fā)過程,SpringBoot也是一個(gè)服務(wù)于框架的框架,服務(wù)范圍是簡(jiǎn)化配置文件。
以上就是關(guān)于“SpringBoot中如何利用Junit實(shí)現(xiàn)單元測(cè)試”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。