在spring中使用junit测试
来源:互联网 发布:淘宝分析软件 编辑:程序博客网 时间:2024/05/22 15:30
1.需要导入的jar包:
spring-test-xxx.jar
junit.jar
2.在junit类前需要添加@RunWith和@ContextConfiguration两个注解
@RunWith 注释标签是 Junit 提供的,用来说明此测试类的运行者,这里用了 SpringJUnit4ClassRunner,这个类是一个针对 Junit 运行环境的自定义扩展,用来标准化在 Spring 环境中 Junit4.5 的测试用例,例如支持的注释标签的标准化。
@ContextConfiguration 注释标签是 Spring test context 提供的,用来指定 Spring 配置信息的来源,支持指定 XML 文件位置或者 Spring 配置类名,根据spring配置文件的位置,locations 有两种参数classpaths以及file。
@RunWith(SpringJUnit4ClassRunner.class)
如果spring配置文件在WEB-INF下,locations使用file
@ContextConfiguration(locations = {“file:WebRoot/WEB-INF/spring-mvc/dispatcher-servlet.xml”})
如果spring配置文件在src下,locations使用classpath
@ContextConfiguration(locations = {“classpath:/spring-mvc/dispatcher-servlet.xml”})
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"file:WebRoot/WEB-INF/spring-mvc/dispatcher-servlet.xml"}) public class plateDaoTest { @Resource private PlateDao plateDao; @Test public void test() { fail("Not yet implemented"); } @Test public void addPlateTest(){ Plate plate = new Plate(); /**setter赋值*/ plateDao.add(plate); }}
0 0
- 在spring中使用junit测试
- Junit在Spring中测试
- 关于在eclipse中使用Spring+JUnit时,JUnit找不到测试类的问题
- 在spring中编写junit测试单元
- junit 测试spring-test 代码!在项目中运行测试通过,留着以后直接使用
- 在eclipse中使用junit测试
- 在Android中使用Junit测试注意事项
- 在Android Studio中使用JUNIT测试
- 在Eclipse中开发使用Spring IOC的JUnit/TestNG测试用例之详解
- 在Eclipse中开发使用Spring IOC的JUnit/TestNG测试用例之详解
- spring使用自动注解在JUNIT下测试
- 使用junit进行Spring测试
- 在IDEA中使用JUnit进行方法测试
- 在IDEA中使用JUnit进行方法测试
- 在Spring应用中使用junit进行单元测试
- Android中使用JUnit测试
- Java中使用JUnit测试
- java中使用junit测试
- Swift学习 结构体、枚举、类三者的对比
- 欢迎使用CSDN-markdown编辑器
- VS2010设置全局Include和Lib目录
- iframe与主框架跨域相互访问方法
- Web Animations
- 在spring中使用junit测试
- Ubuntu下安装ss客户端
- Shiro系列之Shiro+Mysql实现用户授权(Authorization)
- C#学习之操作excel表格
- 使用phpmyadmin导入大量数据
- jsoncpp的简单使用
- Scala练习题02:列表中找出倒数第二个元素
- Java基础(4):类
- 微信网页授权获取用户基本信息