您的位置:首页 > 编程语言 > Java开发

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{
//具体的业务
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: