首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

在Spring框架上 使用junit进行单元测试

2012-10-09 
在Spring框架下 使用junit进行单元测试package com.yourPackage.testimport static org.junit.Assert.*i

在Spring框架下 使用junit进行单元测试

package com.yourPackage.test;

import static org.junit.Assert.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.yourPackage.service.ServiceA;
import com.yourPackage.service.ServiceB;

public class MyTest {
??? private PnlCachingService caching;
??? private PnlHistoricalService hist;
??? @Before
??? public void setUp() throws Exception {
??? ??? ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"file:WebContent/WEB-INF/applicationContext.xml"});
??? ??? BeanFactory factory = (BeanFactory) context;
??? ??? serviceA = (ServiceA) factory.getBean("ServiceA");
??? ??? serviceB = (ServiceB) factory.getBean("ServiceB");
??? }

??? @Test
??? public void testYourService(){
??? ???
??? ??? try{
??? ??? ??? List rtnA = serviceA.functionA();
??? ??? ??? List rtnB = serviceB.functionB();
??? ??? ??? Assert.assertEquals(rtnA, rtnB);
??? ??? }catch (Exception e){
??? ??? ??? e.printStackTrace();
??? ??? }
??? }
}

热点排行