国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 隆尧县| 贡山| 伊川县| 梅州市| 宝山区| 桦甸市| 潞西市| 漯河市| 阿拉善盟| 永宁县| 松阳县| 兰州市| 四子王旗| 桐庐县| 芒康县| 奉化市| 云林县| 米泉市| 光山县| 玉龙| 青冈县| 涿州市| 开封县| 滦平县| 仁寿县| 咸宁市| 深水埗区| 城口县| 大埔区| 西吉县| 珠海市| 阿瓦提县| 遵化市| 乐山市| 广州市| 吉木萨尔县| 铁岭市| 上犹县| 临武县| 右玉县| 清原|