spring整合junit进行测试
以下只是一个模板,大家记得改变配置文件
package cn.itcast.crm.dao; 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 cn.itcast.crm.entity.Customer; @ContextConfiguration(locations= {"classpath:applicationContext_dao.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class CustomerDaoImplTest { /*
* @Test
* public void test() { ApplicationContext ac=new
* ClassPathXmlApplicationContext("classpath:applicationContext_dao.xml");
* CustomerDao customerDao = (CustomerDao) ac.getBean("customerDao"); Customer
* customer = customerDao.findCustomerById(23L); System.out.println(customer); }
*/
@Autowired
private CustomerDao customerDao; @Test
public void test() {
Customer customer = customerDao.findCustomerById(23L);
System.out.println(customer);
} }
spring整合junit进行测试的更多相关文章
- spring 整合junit进行测试
如果想让junit和spring容器环境无缝对接的话,可以使用如下方式: import com.jd.ptest.service.ICronService; import org.junit.Test ...
- Spring整合junit测试
本节内容: Spring整合junit测试的意义 Spring整合junit测试 一.Spring与整合junit测试的意义 在没整合junit之前,我们在写测试方法时,需要在每个方法中手动创建容器, ...
- 原创:Spring整合junit测试框架(简易教程 基于myeclipse,不需要麻烦的导包)
我用的是myeclipse 10,之前一直想要用junit来测试含有spring注解或动态注入的类方法,可是由于在网上找的相关的jar文件进行测试,老是报这样那样的错误,今天无意中发现myeclips ...
- spring整合junit报错
1.Could not autowire field: private javax.servlet.http.HttpServletRequest 参考:https://www.cnblogs.com ...
- 阶段3 2.Spring_06.Spring的新注解_8 spring整合junit完成
Junit的核心Runner在执行的时候不会创建容器.同时它字节码文件,也改不了 spring整合junit 想办法把junit里面的不能加载容器的main方法换掉.从而实现创建容器.有了容器就可以实 ...
- SSM框架中测试单元的使用,spring整合Junit
测试类中的问题和解决思路 3.1.1 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicatio ...
- Spring的AOP开发入门,Spring整合Junit单元测试(基于ASpectJ的XML方式)
参考自 https://www.cnblogs.com/ltfxy/p/9882430.html 创建web项目,引入jar包 除了基本的6个Spring开发的jar包外,还要引入aop开发相关的四个 ...
- Spring整合Junit框架
一.开发环境 eclipse版本:4.6.1 maven版本:3.3.3 junit版本:4.12 spring版本:4.1.5.RELEASE JDK版本:1.8.0_111 二.项目结构 图 三. ...
- Spring整合Junit框架进行单元测试Demo
一.开发环境 eclipse版本:4.6.1 maven版本:3.3.3 junit版本:4.12 spring版本:4.1.5.RELEASE JDK版本:1.8.0_111 二.项目结构 图 三. ...
随机推荐
- 【设计模式+原型理解】第三章:javascript五种继承父类方式
[前言] 我们都知道,面向对象(类)的三大特征:封装.继承.多态 继承:子类继承父类的私有属性和公有方法 封装:把相同的代码写在一个函数中 多态: ->重载:JS严格意义上是没有重载,但可以通过 ...
- python实现某目录下将多个文件夹内的文件复制到一个文件夹中
现实生活中,我们经常有这样的需求,如下图,有三个文件夹,文件夹1内含有1.txt文件 文件夹2中内含有2.txt文件,文件夹3中含有3.txt文件.我们有时候需要把1.txt, 2.txt, 3.tx ...
- git操作常用命令
一.使用git 1.git是什么? Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己 ...
- 部署 apply plugin: 'realm-android'
我在build.gradle中添加 apply plugin: 'realm-android' //依赖Realm数据库,插件化依赖 这个后,同步,清理,运行的时候报 应该在build.gradle ...
- MyBatis学习---逆向工程 Mybatis Generator代码生成
[目录]
- 一起学Android之Layout
本文简述在Android开发中布局的简单应用,属于基础知识,仅供学习分享使用. 概述 在Android UI开发中,布局类型主要有两种:LinearLayout(线性布局)和RelativeLayou ...
- Unity 协同程序
定义协同程序: IEnumerator test() { Debug.log("test 1"); yeild return WaitForSecond(3.0f); Debug. ...
- HTML+Css让网页自动适应电脑手机屏幕
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...
- nginx 配置 rewrite 跳转
在访问 test.com 网站时,会自动跳转到 www.test.com ,这是因为该网站做了 URL rewrite 重定向,一般网页重定向跳转分为两种,301 和 302 :301,302 都是H ...
- 移动端左右滑动问题-html与css解决
<!DOCTYPE html> <html> <head> <title>纯css实现左右滑动</title> <style type ...