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

首頁 > 學院 > 開發設計 > 正文

Spring集成單元測試

2019-11-11 01:17:27
字體:
來源:轉載
供稿:網友

SPRing集成單元測試

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

Spring集成單元測試第一步導入jar包第二步創建一個類第三步集成Spring單元測試第四步編寫測試代碼

第一步:導入jar包

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

第二步:創建一個類

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

第三步:集成Spring單元測試

// 設置Spring單元測試運行環境@RunWith(SpringJUnit4ClassRunner.class)// 設置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;// 設置Spring單元測試運行環境@RunWith(SpringJUnit4ClassRunner.class)// 設置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" /> 也可以注入依賴。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀宁县| 彰化县| 嘉峪关市| 丰台区| 兰西县| 科技| 邢台县| 新化县| 新泰市| 建水县| 那曲县| 林甸县| 绥中县| 武威市| 常德市| 平陆县| 广平县| 永清县| 揭西县| 中超| 堆龙德庆县| 革吉县| 桐柏县| 漠河县| 宜州市| 呼伦贝尔市| 林州市| 马边| 若羌县| 天气| 右玉县| 丰县| 无为县| 关岭| 汝阳县| 普格县| 施秉县| 乌拉特后旗| 海安县| 克东县| 拜城县|