Junit4 + Spring 2.5 : Asserts throw “NoClassDefFoundError”

戏子无情 提交于 2019-12-05 07:59:59

http://jira.springframework.org/browse/SPR-5145

It is an known issue with spring-test 2.5.x. It is incompatible with JUnit 4.5. Use 4.0-4.4.

Or you can try the patch in the issue tracker.

I had the same problem when I wrote my Spring JUnit tests. Like a lot of posts available online, there are only two alternatives

1) Stay up to date with the Spring version and use the latest version of JUnit or 2) Leave your current Spring version and use JUnit version 4.4 or less.

I chose the option # 2 where we left our Spring version at 2.5 and downloaded JUnit 4.4. Everything worked fine after that.

Also another point to be aware of is that if your project i.e., the project A you are writing your tests in has a dependency on another project B that has another version of Spring, you would get a similar error too. I learnt it the hard way.

-Prashanth

What if you imported AssumptionViolatedException into your test class?

It looks like it can't find the class to throw the appropriate exception.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!