国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Spring集成單元測試

2019-11-11 01:55:27
字體:
供稿:網(wǎng)友

SPRing集成單元測試

@(Spring)[單元測試, Spring, 集成]

Spring集成單元測試第一步導(dǎo)入jar包第二步創(chuàng)建一個類第三步集成Spring單元測試第四步編寫測試代碼

第一步:導(dǎo)入jar包

Spring單元測試需要導(dǎo)入spring-test-4.x.x.RELEASE.jarjunit4的jar包

第二步:創(chuàng)建一個類

public class Test1 { public void test1() { }}

第三步:集成Spring單元測試

// 設(shè)置Spring單元測試運(yùn)行環(huán)境@RunWith(SpringJUnit4ClassRunner.class)// 設(shè)置Spring配置文件@ContextConfiguration("classpath:applicationContext.xml")public class Test1 { @Test public void test1() { }}

第四步:編寫測試代碼

package com.pc.crm.test;import java.util.List;import javax.annotation.Resource;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.pc.crm.domain.Customer;import com.pc.crm.service.CustomerService;// 設(shè)置Spring單元測試運(yùn)行環(huán)境@RunWith(SpringJUnit4ClassRunner.class)// 設(shè)置Spring配置文件@ContextConfiguration("classpath:applicationContext.xml")public class Test1 { /** * 注入依賴 */ @Resource(name = "customerService") private CustomerService customerService; @Test public void test1() { List<Customer> list = customerService.findAllCustomer(); System.out.println(list); }}

PS:單元測試中不需要使用注解掃描<context:annotation-config/><context:component-scan base-package="com.xx" /> 也可以注入依賴。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 三门县| 贡嘎县| 临城县| 弋阳县| 海盐县| 永春县| 渑池县| 灵璧县| 龙游县| 潼南县| 禄劝| 虎林市| 禄丰县| 定远县| 宾阳县| 霍林郭勒市| 曲松县| 公安县| 安溪县| 澄迈县| 洪湖市| 永修县| 红安县| 昌都县| 沧州市| 明光市| 南充市| 侯马市| 体育| 广南县| 南部县| 洪泽县| 健康| 富民县| 钟山县| 邳州市| 德阳市| 会东县| 明星| 井陉县| 河北区|