spring 整合junit进行测试
2024-10-19 06:18:15
如果想让junit和spring容器环境无缝对接的话,可以使用如下方式:
import com.jd.ptest.service.ICronService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.junit.Assert.*; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"}) //此处读取spring的配置文件
public class CronServiceImplTest { @Autowired
@SuppressWarnings("all")
ICronService cronService; @Test
public void addCron() {
try
{
cronService.addCron();
} catch (Exception e)
{
e.printStackTrace();
}
}
}
最新文章
- Yii框架CURD方法
- alias指令:设置命令别名
- Rigidbody相关的操作最好放在FixedUpdate中,update中可能会无效果
- axis
- onresize方法
- mfc学生成绩录入与查询
- MFC 构建、消亡 顺序 (一)--单文档 (SDI)
- WebService学习之四:关于JAX-WS 注释
- openwrt opkg update wget returned 4 wget returned 1
- java集合概念
- Css 之 px em %
- 阿里云oss总是提示SignatureDoesNotMatch错误怎么办
- Linux系统操作指令汇总
- php 使用composer
- HTML,js的基础知识
- Redhat 7 开通防火墙端口
- 【 js 工具 】如何使用Git上传本地项目到github?(mac版)
- google-gson 使用及GsonBuilder设置
- iOS绘图UIBezierPath 和 Core Graphics框架
- si4438 cca 侦听
热门文章
- 【Java并发核心九】并发集合框架
- SpringBoot学习历程
- 一道有意思的找规律题目 --- CodeForces - 964A
- BZOJ.4446.[SCOI2015]小凸玩密室(树形DP)
- BZOJ.4199.[NOI2015]品酒大会(后缀数组 单调栈)
- MySQL 一对多查询
- 2009 ACM 水题
- 【DWM1000】 code 解密3一ANCHOR RUN起来
- 潭州课堂25班:Ph201805201 django框架 第十一课 保持登录,注册,登录 (课堂笔记)
- Usaco 4.3.1 Buy Low, Buy Lower 逢低吸纳详细解题报告