一。应用场景:普通java web集成spring test,

  项目结构:使用的是加入jar的方式,不是maven加入依赖的方式

  注意:如果是引入jar包的方式,例如:spring-test4.0.5.jar 和junit4.12.jar的方式,

  如果是使用的是junit4.12.jar的版本,要加入 hamcrest-core1.3.jar包,否则报如下错误:

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test], {ExactMatcher:fDisplayName=test(org.devin.hellochat.test.Test)], {LeadingIdentifierMatcher:fClassName=org.devin.hellochat.test.Test,fLeadingIdentifier=test]] from org.junit.internal.requests.ClassRequest@31befd9f
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

二。使用:

1.applicationContext.xml spring-mvc.xml配置文件放在resource源文件下,注意:web.xml文件需要配置<Context-param></Context-param>,并引入applicationContext.xml文件,

sevlet配置中需要初始化spring-mvc.xml文件

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration({"classpath:applicationContext.xml","classpath:spring_mvc.xml"})  

public class Test{

  @Automired

  private ItemCatService itemCatService;

  @Test

  public void test(){

    System.out.println(itemCatService)

  } 

 }

2.applicationContext.xml spring-mvc.xml配置文件放在WEB-INF目录下:

  

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration({"file:WebContent/WEB-INF/applicationContext.xml","file:WebContent/WEB-INF/spring_mvc.xml"})  

public class Test{

  @Automired

  private ItemCatService itemCatService;

  @Test

  public void test(){

    System.out.println(itemCatService)

  } 

 }

Spring与junit4集成测试的更多相关文章

  1. 一文教会你如何在 Spring 中进行集成测试,太赞了

    不得不说,测试真的是太重要了!但并不是所有的开发者都这样认为,这种感觉在我回到洛阳后尤其强烈.竟然有团队成员不经测试就把代码提交到代码库,并且是会报错的那种,我天呐,遇到这种队友我也是醉了. 我之前是 ...

  2. 利用Spring的junit4测试

    利用Spring的JUnit4进行测试 不需要再显式创建Spring容器和getBean @RunWith(SpringJUnit4ClassRunner.class) @ContextConfigu ...

  3. Spring整合Junit4

    1.加入相应依赖包 junit4-4.7.jar 以及spring相关jar包 2.在测试代码的源码包中如 src/test/java 新建一个抽象类如下 import org.junit.runne ...

  4. web项目中 集合Spring&使用junit4测试Spring

    web项目中 集合Spring 问题: 如果将 ApplicationContext applicationContext = new ClassPathXmlApplicationContext(& ...

  5. Spring 整合 Junit4 进行单元测试

    1. pom.xml 引入JAR依赖: <dependency> <groupId>junit</groupId> <artifactId>junit& ...

  6. Spring整合JUnit4进行AOP单元测试的时候,报:"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3\lib\idea_rt.jar=64

    错误代码 "C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size= ...

  7. Spring Test+JUnit4整合使用测试ZZJ_淘淘商城项目:day01(RESTful Web Service)

    针对整合的Dao层与Service层,在做spring与通用Mapper和分页插件相关测试时比较麻烦.如果只用JUnit测试,需要每次Test方法里初始化一下applicationContext,效率 ...

  8. Spring整合JUnit4测试

    @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:spring/ap ...

  9. Spring MVC Junit4 单元測试 JunitTest

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSmVyb21lX3M=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

随机推荐

  1. 解决Hash碰撞冲突的方法

    Hash碰撞冲突 我们知道,对象Hash的前提是实现equals()和hashCode()两个方法,那么HashCode()的作用就是保证对象返回唯一hash值,但当两个对象计算值一样时,这就发生了碰 ...

  2. Golang的goroutine协程和channel通道

    一:简介 因为并发程序要考虑很多的细节,以保证对共享变量的正确访问,使得并发编程在很多情况下变得很复杂.但是Go语言在开发并发时,是比较简洁的.它通过channel来传递数据.数据竞争这个问题在gol ...

  3. 日常小节----unity小坑记(静态后不可移动和旋转)

    当物体被置为静态时,模型网格是无法移动和旋转的,只有碰撞器可以. 也就是会出现当父物体不为静态,子物体为静态时,运行后旋转移动父物体,子物体模型网格不会跟随旋转移动,但子物体碰撞器会跟随旋转移动. 或 ...

  4. javaweb期末项目-项目结构

    相关链接: 项目结构:https://www.cnblogs.com/formyfish/p/10828672.html 需求分析:https://www.cnblogs.com/formyfish/ ...

  5. SpringBoot + thymeleaf 实现分页

    SpringBoot结合Thymeleaf实现分页,很方便. 效果如下 后台代码 项目结构 1. 数据库Config 由于hibernate自动建表字符集为latin不能插入中文,故需要在applic ...

  6. 安装mistral

    1.安装mistral安装包 yum -y install openstack-mistral-api.noarch openstack-mistral-engine.noarch openstack ...

  7. 【VS开发】【编程开发】【C/C++开发】结构体中的数组与指针的内存分配情况说明

    [VS开发][编程开发][C/C++开发]结构体中的数组与指针的内存分配情况说明 标签:[VS开发] [编程开发] 主要是疑惑在结构体定义的数组的内存空间与指针动态分配的内存空间,在地址上连续性.以及 ...

  8. 【机器学习】Matlab中实现QQ-plot的一个好工具gqqplot

    Matlab中实现QQ-plot的一个好工具gqqplot 26JUN June 26, 2013 这几天看了一下QQ-plot以及在Matlab中的实现,可是Matlab自带的qqplot函数不能满 ...

  9. TP5 isEmpty() 判空方法 所用场景

    1, { }类型 { "id": 1, "name": "首页置顶", "description": "首页轮 ...

  10. Oracle数据库弱口令解密

    1.首先我们先看下Oracle加密的格式. 接下来我们把他头和尾部删除,中间加: 通过py脚本来进行完成 转换完成后输出成这种格式 之后直接丢进kali里面,用john --w=字典文件 + 转换文件 ...