首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JUnit与Spring的调整

2012-09-06 
JUnit与Spring的整合package com.business.serviceimport org.junit.Testimport org.springframework.te

JUnit与Spring的整合

package com.business.service;import org.junit.Test;import org.springframework.test.AbstractDependencyInjectionSpringContextTests;import com.business.service.BrokerManagerService;public class DeployManagerActionTestCase extends AbstractDependencyInjectionSpringContextTests{        private BrokerManagerService brokerManagerService;    public BrokerManagerService getBrokerManagerService()    {        return brokerManagerService;    }    public void setBrokerManagerService(BrokerManagerService brokerManagerService)    {        this.brokerManagerService = brokerManagerService;    }    @Override    protected String[] getConfigLocations()    {        return new String[]{"file:F:\\wmba\\src\\applicationContext.xml","file:F:\\wmba\\src\\applicationContext-wmba.xml"};    }    public void testDeployManagerMethod(){        System.out.println("--->"+brokerManagerService);    }}


1.上面文件路径可以为其他写法,不过我对路径不熟,所以把路径写死了!!!

2.brokerManagerService属性在Spring文件中有配置,可以注入进来.....

3.AbstractDependencyInjectionSpringContextTests继承了这个类,那么就不能给测试方法加@Test注解了,只能给方法名称前加上test......

----------所使用的架包为:spring-test.jar、junit-4.1.jar

热点排行