package test;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import com.etone.service.ICacheService;
public class junitTest {
@Test
public void test() throws Exception {
// String[] clapath = { "classpath:applicationContext-hibernate.xml" };
// ApplicationContext context= new
ClassPathXmlApplicationContext(clapath
);//加载classpath下文件也就是Web-INF/classes下的文件
String local = "WebRoot/WEB-INF/applicationContext-hibernate.xml";
ApplicationContext context = new FileSystemXmlApplicationContext(local);
//cacheService为applicationContext-hibernate.xml中的bean的id 可以对应Dao也可以对应service层bean的id
ICacheService cs = (ICacheService) context.getBean("cacheService");
cs.createBussinessCacheData();
}
}
本文介绍了一个使用JUnit进行单元测试的具体案例。通过加载Spring上下文,获取业务服务,并调用其方法来创建业务缓存数据。该示例展示了如何在Java项目中集成JUnit和Spring框架。
9680

被折叠的 条评论
为什么被折叠?



