Spring4.3.0 Junit4.11 initializationError(org.junit.runner.manipulation.Filter)

本文主要是介绍Spring4.3.0 Junit4.11 initializationError(org.junit.runner.manipulation.Filter),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Spring4.3.0 Junit4.11 initializationError(org.junit.runner.manipulation.Filter)

昨天手欠,在项目中把Spring3.2.14版本升级到4.3.0版本,结果在使用junit进行单元测试时抛出如下错误,耗了一个多小时才搞定,在此记录一下,以防遗忘。

具体解决方案:升级Junit4.11版本到4.12版本解决,初步怀疑是底层实现方式不兼容导致,但还没深究代码实现,不作100%保证

package com.mhy.aop;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.mhy.aop.aspectj.PreGreetingAspect;
import com.mhy.aop.aspectj.service.WaiterService;
import com.mhy.aop.aspectj.service.impl.WaiterServiceImpl;/*** 增强类测试* @author mahaiyuan* @date 2016年7月2日 下午11:52:36*/
@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration(locations = "classpath:aspectj-beans.xml")
public class AspectJTest {@Autowiredprivate WaiterService waiterService;@Testpublic void test02(){waiterService.greetTo("王五");System.out.println("============================");waiterService.serveTo("赵六");}
}

执行测试用例时,在eclipse里显示执行失败
单元测试失败
竟然没有错误提示?!拷贝了一下该异常信息,具体内容如下:

AspectJTest.test02
initializationError(org.junit.runner.manipulation.Filter)
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test02], {ExactMatcher:fDisplayName=test02(com.mhy.aop.AspectJTest)], {LeadingIdentifierMatcher:fClassName=com.mhy.aop.AspectJTest,fLeadingIdentifier=test02]] from org.junit.internal.requests.ClassRequest@579bb367at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)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)

大致的意思是没有找到匹配的测试方法,但明明有,为什么会说没有匹配上呢?
从google和stackoverflow查找了一翻,大部分都在写换IDE、重写RunWith下的类等等,不一而足,但最终没能解决这个问题,个人也感觉不靠谱,没办法只能回到实际情况本身来反向推论了。

产生原因:升级Spring的版本之后单元测试不能使用了
那如果把版本降为3.2.14是否还能正常,测试了一下,把版本降为3.2.14之后测试用例能正常执行了,那是否为Spring4与Junut4.11版本的兼容性问题呢?比如底层实现方式发生了变化,然后把项目中使用的Junit版本升级到4.12。

升级之后再次执行该测试用例,然后内牛满面了,结果运行正常

How are you
WaiterServiceImpl.greetTo name=王五
============================
WaiterServiceImpl.serveTo name=赵六

根据当前的情况来讲,问题产生在Spring与Junit不同版本之间的兼容性方面,具体是哪一步实现不兼容导致在未看底层实现方面不能保证具体原因,待后面查看源码时再补充上该内容。^_^

这篇关于Spring4.3.0 Junit4.11 initializationError(org.junit.runner.manipulation.Filter)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/986033

相关文章

Spring Boot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)

《SpringBoot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)》:本文主要介绍SpringBoot拦截器Interceptor与过滤器Filter深度解析... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实

解决tomcat启动时报Junit相关错误java.lang.ClassNotFoundException: org.junit.Test问题

《解决tomcat启动时报Junit相关错误java.lang.ClassNotFoundException:org.junit.Test问题》:本文主要介绍解决tomcat启动时报Junit相... 目录tomcat启动时报Junit相关错误Java.lang.ClassNotFoundException

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

Spring Boot拦截器Interceptor与过滤器Filter详细教程(示例详解)

《SpringBoot拦截器Interceptor与过滤器Filter详细教程(示例详解)》本文详细介绍了SpringBoot中的拦截器(Interceptor)和过滤器(Filter),包括它们的... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)详细教程1. 概述1

dubbo3 filter(过滤器)如何自定义过滤器

《dubbo3filter(过滤器)如何自定义过滤器》dubbo3filter(过滤器)类似于javaweb中的filter和springmvc中的intercaptor,用于在请求发送前或到达前进... 目录dubbo3 filter(过滤器)简介dubbo 过滤器运行时机自定义 filter第一种 @A

Java 8 Stream filter流式过滤器详解

《Java8Streamfilter流式过滤器详解》本文介绍了Java8的StreamAPI中的filter方法,展示了如何使用lambda表达式根据条件过滤流式数据,通过实际代码示例,展示了f... 目录引言 一.Java 8 Stream 的过滤器(filter)二.Java 8 的 filter、fi

org.hibernate.hql.ast.QuerySyntaxException:is not mapped 异常总结

org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [select u from User u where u.userName=:userName and u.password=:password] 上面的异常的抛出主要有几个方面:1、最容易想到的,就是你的from是实体类而不是表名,这个应该大家都知道,注意

Caused by: org.hibernate.MappingException: Could not determine type for: org.cgh.ssh.pojo.GoodsType,

MappingException:这个主要是类映射上的异常,Could not determine type for: org.cgh.ssh.pojo.GoodsType,这句话表示GoodsType这个类没有被映射到