码迷,mamicode.com
首页 > 其他好文 > 详细

单元测试环境

时间:2016-05-28 17:32:17      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

1.新建LoadPropertis类,内容如下:

import org.springframework.context.support.ClassPathXmlApplicationContext;

import junit.framework.TestCase;

public class LoadPropertis extends TestCase{
private static ClassPathXmlApplicationContext context= null;
private static String allproperties[] = {
"applicationContext-channel-test.xml","applicationContext-common-test.xml"
};
protected void setUp() throws Exception{
super.setUp();
if(context==null){
context = new ClassPathXmlApplicationContext(allproperties);
}
}
protected void tearDown() throws Exception{
super.tearDown();
}
protected Object getBean(String beanName){
if(beanName == null){
throw new IllegalArgumentException(beanName + "is null");
}
return context.getBean(beanName);
}
}

 

2.新建:Test01类,内容如下:

public class Test01 extends LoadPropertis {

private IZybCoreBS zybCoreBS;

protected void setUp() throws Exception{
super.setUp();
zybCoreBS = (IZybCoreBS)this.getBean("zybCoreBS");
}

protected void tearDown()throws Exception{
super.tearDown();
}

public void test01() {

CurrAccoInVo currAccoInVo = new CurrAccoInVo();

try {
zybCoreBS.currAccoQuery(currAccoInVo);
} catch (Exception e) {
System.out.println("失败");
}

}

}

 

3.配置文件:application-channel-test.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<bean id="zybCoreBS" class="com.tansun.scf.zyb.intf.core.service.impl.ZybCoreBSImpl">
<property name="bussCommonBS">
<ref bean="bussCommonBS" />
</property>
</bean>

<bean id="zybCmsBS" class="com.tansun.scf.zyb.intf.cms.service.impl.ZybCmsBSImpl">
<property name="bussCommonBS">
<ref bean="bussCommonBS" />
</property>
</bean>

<bean id="bussCommonBS" class="com.tansun.scf.common.service.impl.BussCommonBSImpl">
<property name="sysparamBS">
<ref bean="sysparamBS" />
</property>
</bean>

</beans>

 

4.配置文件applicationContext-common-test.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="jndiDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>OracleDataSource</value>
</property>
</bean>

<bean id="lobHandler"
class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>

 

 

</beans>

 

其中applicationContext-common-test.xml是放数据库配置文件和数据库表xml文件目录的,

applicationContext-channel-test.xml是放调用java类的bean配置信息的

单元测试环境

标签:

原文地址:http://www.cnblogs.com/lufm/p/5537606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!