[Junit]单元测试报错java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException

  • 今天在写单元测试时,出现一个报错,具体现象如下:

1.Junit依赖:

        
            junit
            junit
            4.12
            test
        

2.spring版本:


[Junit]单元测试报错java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException_第1张图片

3.当通过spring注入服务,并调用服务接口时,比如dubbo/HSF或者其他RPC类的服务框框架暴露的接口时,会报错:java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException,截图如下:


[Junit]单元测试报错java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException_第2张图片

4.通过排除法定位到引起报错的代码:

public class AuthorizedServiceTest extends BaseTest {

    @Resource
    private AuthorizeService authorizeService;

    @Test
    public void authorizeMemberTest() {
        ......

        Result result = authorizeService.authorizeMember(credentials);

        ......
    }
}
  • 问题原因:
    参考http://forum.spring.io/forum/spring-projects/container/52022-spring-test-breaks-in-junit-4-5,才知道spring-test 2.5版本必须配合Junit4.4版本使用

  • 解决方法:
    修改Junit版本为4.4,或者升级spring-test版本,这里我采用的是前一种方法

        
            junit
            junit
            4.4
            test
        

修改后,不再报错了

你可能感兴趣的:([Junit]单元测试报错java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException)