spring使用自动注解在JUNIT下测试

来源:互联网 发布:js img中心不停的旋转 编辑:程序博客网 时间:2024/06/05 10:01

这是去年做练习时候整理出来的笔记了,趁着今天有空整理出来。

由于使用了Spring的注解功能,所以在单元测试时候,要先加载配置文件,不然的话肯定是报错的。

只需要在测试类外加入

如:

import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

//test类自动加载xml文件
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({
    "classpath:spring.xml",
    "classpath:hibernate-spring.xml"
})


public class LineTest {

 @Resource
    LineService service;

@Test
    public void testCheckLineByParam() {
        System.out.println(service.checkLineByTname("1008").size());
    }

}

0 0