Spring下的单元测试(JUnit)--加载配置文件
2012-08-31 10:15
549 查看
最近在调研JUnit单元测试。因为分层的关系,涉及到很多的Spring注入,在底层业务类测试的时候发现需要读取Spring的一些配置文件。
以下是读取配置文件的例子:
以下是读取配置文件的例子:
import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; import org.hibernate.SessionFactory; import org.hibernate.classic.Session; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestService { private ApplicationContext ac; @Before public void setUp() throws Exception{ ac = new ClassPathXmlApplicationContext("config/*.xml"); } @Test public void TestApplicationInfoSucess() throws Exception{ //具体的业务 } }
相关文章推荐
- Spring单元测试加载配置文件启动异常
- junit进行测试加载多个spring配置文件
- Junit单元测试Spring 读取WEB-INF下的配置文件
- spring 配置文件无法加载,junit找不到xml配置文件java.lang.IllegalStateException: Failed to load ApplicationContext
- Junit手动/自动加载spring配置文件
- junit测试用例加载spring配置文件
- Junit手动/自动加载spring配置文件
- Junit单元测试Spring 读取WEB-INF下的配置文件
- spring中用JUnit做单元测试时多个spring配置文件的引入
- 加载spring配置文件的常用三种方法
- spring中加载xml配置文件的方式
- web.xml文件中配置(servlet, spring, filter, listenr)的加载顺序研究
- spring boot启动时加载外部配置文件的方法
- spring-自动加载配置文件\使用属性文件注入
- spring-boot 加载本地静态资源文件路径配置
- Spring的 classpath 通配符加载配置文件
- Spring中加载配置文件的方式
- IDEA spring的xml配置文件加载不到properties属性问题
- Spring中加载xml配置文件的六种方式
- 请慎用spring-ClassPathXmlApplicationContext手动加载spring配置文件