一、注解方式测试

1、注解方式测试使用junit。使用junit-4.12.jar和hamcrest-all-1.3.jar(单元测试包)

把这两个jar包,导入到lib文件夹下。

2、TestSpring测试

使用注解:

@RunWith(SpringJUnint4ClassRunner.class):表示这是一个Spring的测试类

@ContextConfiguration("classpath:applicationContext.xml"):定位Spring的配置文件

@Autowired:给这个测试类注入Product对象

@Test:逻辑测试,打印Product对象的name

package com.demo.test;

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 com.demo.pojo.Product; @RunWith(SpringJUint4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestSpring{
@Autowired
Product product; @Test
public void test(){
System.out.println(product.getName());
}
}

十九、Spring框架(注解方式测试)的更多相关文章

  1. mybatis源码学习--spring+mybatis注解方式为什么mybatis的dao接口不需要实现类

    相信大家在刚开始学习mybatis注解方式,或者spring+mybatis注解方式的时候,一定会有一个疑问,为什么mybatis的dao接口只需要一个接口,不需要实现类,就可以正常使用,笔者最开始的 ...

  2. Spring框架下Junit测试

    Spring框架下Junit测试 一.设置 1.1 目录 设置源码目录和测试目录,这样在设置产生测试方法时,会统一放到一个目录,如果没有设置测试目录,则不会产生测试代码. 1.2 增加配置文件 Res ...

  3. (转)使用Spring的注解方式实现AOP的细节

    http://blog.csdn.net/yerenyuan_pku/article/details/52879669 前面我们已经入门使用Spring的注解方式实现AOP了,现在我们再来学习使用Sp ...

  4. (转)使用Spring的注解方式实现AOP入门

    http://blog.csdn.net/yerenyuan_pku/article/details/52865330 首先在Eclipse中新建一个普通的Java Project,名称为spring ...

  5. JavaWeb_(Spring框架)注解配置

    系列博文 JavaWeb_(Spring框架)xml配置文件  传送门 JavaWeb_(Spring框架)注解配置 传送门 Spring注解配置 a)导包和约束:基本包.aop包+context约束 ...

  6. spring 纯注解方式 与AOP

    spring注解方式 以前我也使用过纯注解方式.现在在这里做个记录 我们先认识几个我们都耳熟能详的注解 @configuration :从spring3.0这个注解就可以用于定义配置类,可以替换xml ...

  7. 简单实现Spring框架--注解版

    自己写的Spring框架——简单实现IoC容器功能 前几天在网上看了篇帖子,是用xml的方式实现spring的ioc容器,觉得挺有意思的,这边自己试着用注解的形式造了一套轮子. 工程结构 codein ...

  8. Spring的注解方式实现AOP

    Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...

  9. 使用Spring的注解方式实现AOP

    Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...

随机推荐

  1. React生命周期执行顺序详解

    文章内容转载于https://www.cnblogs.com/faith3/p/9216165.html 一.组件生命周期的执行次数是什么样子的??? 只执行一次: constructor.compo ...

  2. docker启动:Got permission denied while trying to connect to the Docker daemon

    权限问题: 1.查看所有用户组与用户 vim /etc/group     /etc/group 的内容包括用户组(Group).用户组口令.GID及该用户组所包含的用户(User),每个用户组一条记 ...

  3. Python安装第三方库的安装技巧

    电脑:Windows10 64位. Python IDE 软件:JetBrains PyCharm Community Edition 2018.1.3 x64 Python version : Py ...

  4. svn的使用教程

    引言:这里只讲解几个svn不常用但是非常有用的使用方法,对于经常使用的不做概述,因为很简单,而且网上都能找到. 1.1 svn历史版本对比已经恢复到指定版本(myeclipse) 在项目中的文件或者文 ...

  5. Xshell5中常用linux服务器命令集合

    简易版:http://www.zhimengzhe.com/linux/84546.html 详细版:http://www.cnblogs.com/peida/tag/%E6%AF%8F%E6%97% ...

  6. MySQL学习(四)

    1 MySQL日期和时间类型 创建一个包含DATE类型的表 mysql> create table test3( -> star varchar(20) not null default ...

  7. 【java】Comparator的用法

    文章转载自: http://blog.csdn.net/u012250875/article/details/55126531 1.为什么写? comparator 是javase中的接口,位于jav ...

  8. MYSQL常用函数(时间和日期函数)

    CURDATE()或CURRENT_DATE() 返回当前的日期 CURTIME()或CURRENT_TIME() 返回当前的时间 DATE_ADD(date,INTERVAL int keyword ...

  9. JAVA基础知识总结:十九

    一.多线程使用过程中的临界资源问题 1.临界资源:被多个线程同时访问的资源 临界资源产生的原因:有多个线程同时访问一个资源的时候,如果一个线程在取值的过程中,时间片又被其他的线程抢走了,临界资源问题就 ...

  10. lua --- __newindex

    -- __newindex 对表进行更新 MyMetatable = {} MyTable = }, {__newindex = MyMetatable}) MyTable.newKey1 = pri ...