spring_JUnit4测试_通过注解加载xml配置_@RunWith_@ContextConfiguration

来源:互联网 发布:芒果tv电视直播软件 编辑:程序博客网 时间:2024/06/07 10:35
public class TestSpring {    @Test    public void test() {            //初始化应用程序上下文对象ApplicationContext ac = new ClassPathXmlApplicationContext("xxx.xml");Abc abc = (Abc) ac.getBean("abc");    }}

使用注解的测试用例
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations=”classpath:xxx.xml”)

@RunWith(SpringJUnit4ClassRunner.class)//让测试运行于spring测试环境@ContextConfiguration(locations="classpath:xxx.xml")//指定 Spring 配置文件所在的位置public class TestSpring {    @Resource    private A a;     @Test    public void test() {    }}
阅读全文
1 0
原创粉丝点击