加入spring test.jar包

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.geyao</groupId><artifactId>spring01geyao</artifactId><version>1.0-SNAPSHOT</version><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.13.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>4.3.13.RELEASE</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency></dependencies></project>

CompactDisc类

package soundSystem;import org.springframework.stereotype.Component;@Component
public class CompactDisc {public CompactDisc() {super();System.out.println("compactdisc无参构造方法");}public void play(){System.out.println("正在播放音乐....");}
}

CDplay类

package soundSystem;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class CDPlayer {private CompactDisc cd;public CDPlayer() {super();System.out.println("CDPlayer无参构造方法");}
@Autowiredpublic CDPlayer(CompactDisc cd) {this.cd = cd;System.out.println("CDPlayer有参构造方法");}public void play(){cd.play();}
}

appconfig类

package soundSystem;import org.springframework.context.annotation.ComponentScan;
//spring注解类
@ComponentScan
public class Appconfig {
}

apptest类

package soundSystem;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;//@RunWith(SpringJunit4ClassRunner.class)
//@ContextConfiguration(class=)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Appconfig.class)
public class AppTest {@Autowiredprivate CDPlayer player;@Testpublic void testPlay(){player.play();}
}

运行结果

[INFO ] 2019-10-29 21:19:35,531 method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:583)
Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@32709393: startup date [Tue Oct 29 21:19:35 CST 2019]; root of context hierarchy
[DEBUG] 2019-10-29 21:19:35,565 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,566 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,602 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,609 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,717 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,718 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,720 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,772 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,773 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,774 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,775 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,792 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,806 method:org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:730)
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@124c278f: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,appconfig,CDPlayer,compactDisc]; root of factory hierarchy
[DEBUG] 2019-10-29 21:19:35,806 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,807 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,810 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 21:19:35,813 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 21:19:35,815 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 21:19:35,825 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.event.internalEventListenerProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,834 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 21:19:35,835 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 21:19:35,836 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 21:19:35,836 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.event.internalEventListenerFactory' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,844 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 21:19:35,846 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'appconfig'
[DEBUG] 2019-10-29 21:19:35,846 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'appconfig'
[DEBUG] 2019-10-29 21:19:35,848 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'appconfig' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,855 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'appconfig'
[DEBUG] 2019-10-29 21:19:35,856 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'CDPlayer'
[DEBUG] 2019-10-29 21:19:35,857 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'CDPlayer'
[DEBUG] 2019-10-29 21:19:35,876 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'compactDisc'
[DEBUG] 2019-10-29 21:19:35,877 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'compactDisc'
compactdisc无参构造方法
[DEBUG] 2019-10-29 21:19:35,878 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'compactDisc' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,885 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'compactDisc'
[DEBUG] 2019-10-29 21:19:35,886 method:org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:757)
Autowiring by type from bean name 'CDPlayer' via constructor to bean named 'compactDisc'
CDPlayer有参构造方法
[DEBUG] 2019-10-29 21:19:35,889 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'CDPlayer' to allow for resolving potential circular references
[DEBUG] 2019-10-29 21:19:35,891 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'CDPlayer'
[DEBUG] 2019-10-29 21:19:35,891 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'compactDisc'
[DEBUG] 2019-10-29 21:19:35,892 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 21:19:35,970 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'lifecycleProcessor'
[DEBUG] 2019-10-29 21:19:35,980 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'CDPlayer'
正在播放音乐....Process finished with exit code 0

spring学习(13):使用junit4进行单元测试续相关推荐

  1. 第四阶段--Spring学习-03

    第四阶段--Spring学习 13.AOP简介 13.1 什么是AOP? 13.2 AOP作用 13.3 AOP核心概念 14.AOP入门案例 14.1 AOP入门案例思路分析 14.2 环境准备 1 ...

  2. Spring + Spring MVC + mybatis 下的 junit4 注入单元测试

    spring环境下的JUnit4测试 1.下载所需jar包: spring-test-4.0.2.RELEASE.jar junit-4.11.jar Maven <dependency> ...

  3. 在Eclipse中使用JUnit4进行单元测试(图文教程一)

    在Eclipse中使用JUnit4进行单元测试 单元测试,JUnit4. 这两个有什么关系呢?这就好比(草)单元测试和(割草机).用这个JUnit4工具去辅助我们进行测试.其实不理解这个也没关系,听多 ...

  4. JavaEE——Spring学习笔记03【AOP开发】

    JavaEE--Spring学习笔记01[Ioc开发的模式] JavaEE--Spring学习笔记02[Spring和Mybatis的整合] JavaEE--Spring学习笔记03[AOP开发] J ...

  5. spring学习12 -Spring 框架模块以及面试常见问题注解等

    以下为spring常见面试问题: 1.Spring 框架中都用到了哪些设计模式? Spring框架中使用到了大量的设计模式,下面列举了比较有代表性的: 代理模式-在AOP和remoting中被用的比较 ...

  6. 在Eclipse中使用JUnit4进行单元测试

    在Eclipse中使用JUnit4进行单元测试 http://www.sina.com.cn  2010年01月18日 14:08  IT168.com [IT168 技术文档]我们在编写大型程序的时 ...

  7. Spring学习笔记1

    前言 Spring框架的学习路线: Spring第一天:Spring的IOC容器之XML的方式,Spring框架与Web项目整合 Spring第二天:Spring的IOC容器之注解的方式,Spring ...

  8. spring学习笔记06-spring整合junit(出现的问题,解决的思路)

    spring学习笔记06-spring整合junit(出现的问题,解决的思路) 文章目录 spring学习笔记06-spring整合junit(出现的问题,解决的思路) 3.1测试类中的问题和解决思路 ...

  9. 【Spring学习笔记 九】Spring声明式事务管理实现机制

    什么是事务?事务就是把一系列的动作当成一个独立的工作单元,这些动作要么全部完成,要么全部不起作用,关乎数据准确性的地方我们一定要用到事务,防止业务逻辑出错. 什么是事务管理,事务管理对于企业应用而言至 ...

最新文章

  1. 窗口函数(防忘笔记)
  2. 在MAC上搭建eclipse+android开发环境以及eclipse的svn插件的安装
  3. Middleware(中间件)
  4. Linux下crontab命令的用法
  5. ArcGIS实验教程——实验十六:空间数据查询
  6. usb长包数据结束判断_如何判断南桥好坏 判断南桥好坏方法介绍【详解】
  7. mysql获取一个表的数据作为值插入_请问如何在mysql中得到一个即将插入数据表中的那条数据的id值(id自增长)?...
  8. Win11怎么打开以前的word文档
  9. C++重载IO操作符
  10. MySQL中Slave_IO_Running: Connecting问题
  11. 【高校宿舍管理系统】第九章 寝室编号设置和宿舍初始化以及预选设置
  12. 如何使用Service的Context弹出Dialog对话框,即全局性对话框
  13. 【noi 2.6_162】Post Office(DP)
  14. MySQL数据库选型
  15. 迷茫了,就带她去一趟阿鲁巴K
  16. 内存对齐以及如何关闭内存对齐
  17. 斐讯N1 docker安装opernwrt,当做旁路由
  18. 输入某年某月某日,判断这一天是这一年的第几天python
  19. 上拉电阻与下拉电阻总结 与 GPIO框图分析
  20. 2021年西式面点师(中级)免费试题及西式面点师(中级)作业考试题库

热门文章

  1. 常见位操作:获取,设置,清零
  2. ajax jq 图片上传请求头_Jquery ajaxsubmit上传图片实现代码
  3. abap al设置单元格可编辑 oo_excel表格操作: 图形和图表编辑技巧汇总(二)
  4. 升级php7_PhpStorm 2019.3 发布,全面支持 PHP 7.4
  5. python 判断字符串是否为空用什么方法?
  6. VSCode摸鱼插件 — FreeWindow
  7. Python的gevent协程及协程概念
  8. 高性能并发TCP网络服务-IOCP框架修正VC2008版本
  9. linux下tree命令详解
  10. ULONGLONG乘法分析