Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring TestContext Framework not compatible with JUnit 4.5 [SPR-5145] #9818

Closed
spring-issuemaster opened this Issue Sep 8, 2008 · 21 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Sep 8, 2008

Alison Rosewarne opened SPR-5145 and commented

After upgrading to junit 4.5 my test class which uses the SpringJUnit4ClassRunner gets a NoClassDefFoundError:

org.apache.maven.surefire.booter.SurefireExecutionException: org/junit/Assume$AssumptionViolatedException; nested exception is java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
java.lang.NoClassDefFoundError: org/junit/Assume$AssumptionViolatedException
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:240)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)

etc.

This is a Junit 4.5 issue. The static class AssumptionViolatedException within org.junit.Assume that existed in 4.4 has become org.junit.internal.AssumptionViolatedException.

The file tiger/mock/org/springframework/test/context/junit4/SpringMethodRoadie.java imports org.junit.Assume.AssumptionViolatedException which is why my test is failing.

Workaround is to stick with Junit 4.4.

(Aside: are there plans to create a "SpringTEST" component?).


Affects: 2.5.5

Attachments:

Issue Links:

  • #9844 Incompatible with JUnit 4.5 ("is duplicated by")
  • #10557 Upgrade the Spring TestContext Framework to JUnit 4.6

Referenced from: commits d159195, c0c9501, 9daae23, e5d2570, 751e0f0, 62c991f, 6327b34

3 votes, 11 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 13, 2008

Henrik Kaipe commented

On top of the patch - make sure you also replace the old spring/lib/junit/junit-4.4.jar with the new junit-4.5.jar, which can be downloaded here:
http://sourceforge.net/project/showfiles.php?group_id=15278&package_id=12472

The patch offers a solution where SpringJUnit4ClassRunner extends the new JUnit4.5 class "BlockJUnit4Runner", which offers much better possibilities for extension and reuse than the old class JUnit4ClassRunner, which have been deprecated.

This also means that backward-compability to JUnit-4.4 is broken but I think it is worth it. Its default class-runner JUnit4ClassRunner was not really supposed to be extended the way SpringJUnit4ClassRunner did it. (Not that there was any good alternative but still ...) Also, by switching to JUnit-4.5 the classes SpringTestMethod and SpringMethodRoadie can be removed.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 14, 2008

Juergen Hoeller commented

I'm afraid we can't move to JUnit 4.5+ in the Spring 2.5.x branch. However, in the upcoming Spring 3.0 branch, we'll build on JUnit 4.5.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 14, 2008

Jaro Kuruc commented

Please make sure you use junit:junit-dep:4.5 rather than junit:junit:4.5. It properly defines a dependency on org.hamcrest:hamcrest-core:1.1 whereas junit:junit:4.5 bundles the classes inside of itself. This causes problems when using org.jmock:jmock-junit4:2.5.1 because hamcrest classes then appear twice on classpath.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 22, 2008

Paul Benedict commented

What prevents the fix in 2.5?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 22, 2008

Juergen Hoeller commented

Well, the 2.5 branch entered strict maintenance mode last week. While we are in principle still able to support new versions of third-party dependencies, we can't raise the minimum level unless the previously supported version was pre-release software. Unfortunately it seems that supporting JUnit 4.5 here means requiring JUnit 4.5+; we can't do that before Spring 3.0 since all sorts of present build and development environments have JUnit 4.4 baked into them. It's unpleasant but not our fault - there was no better way of doing the test context framework against the hard-to-extend JUnit 4.4.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Apr 27, 2009

Sam Brannen commented

Reopening to complete the migration from JUnit 4.4 to JUnit 4.5 including custom Statements and extension of BlockJUnit4ClassRunner.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Apr 29, 2009

Juergen Zimmermann commented

JUnit 4.6 is already available.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Apr 29, 2009

Sam Brannen commented

The Spring TestContext Framework is now based on JUnit 4.5.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 30, 2009

Leo Hart commented

Is there a patch for Spring 2.5.6 and Junit 4.5 available? This one seems to only apply to Spring 2.5.5.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 30, 2009

Sam Brannen commented

Hi Leo,

The patch you're referring to was submitted by Henrik Kaipe in September 2008. Thus if you would like to use his work against Spring 2.5.6, you would need to contact him directly or figure out how to upgrade the patch on your own.

Please note, however, that I upgraded the Spring code base in trunk to work with JUnit 4.5. This code applies to Spring 3.0.0.M3 as well as the upcoming 3.0.0.RC1 and 3.0.0.GA releases. Thus, if you can start using Spring 3.0, you won't need a patch.

Regards,

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 30, 2009

Leo Hart commented

Hi Sam,

Thanks for your reply! Unfortunately I can't go to 3.0 anytime soon. My company is pretty strict about software versions and probably won't be "accepting" 3.0 for some time.

I'm in a bit of a tough spot as we're using the latest version of Concordion to execute spring injected tests. This latest version of Concordion requires the 4.5 version of junit to function, which obviously conflicts with what Spring 2.5.6 needs. Given this combination is only being used in isolated testing, patching the 2.5.6 version shouldn't be blocked by "the man".

I'll try mucking about with the patch. First I need to get the spring sources to compile. build.bat alljars keeps throwing compilation errors (before applying the patch).

Anyways, thanks!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jun 30, 2009

Sam Brannen commented

Leo,

Disclaimer: I've not tried this, and it's not "supported", but...

You could likely take the 2.5.6 build, simply copy the 3.0.0.M3 code for the org.springframework.test package over it, and then create your own "reverse engineered" patch. Obviously the work I did in the 3.0 branch built off the 2.5.6 branch. So theoretically it should work. That might prove easier than reverse engineering the patch in this JIRA, and it would be more likely to be forward compatible.

Good luck in any case!

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jul 2, 2009

Sam Brannen commented

FYI: For those of you still following this issue, the Spring TestContext Framework is now based on JUnit 4.6.0 as of Spring 3.0.0.RC1.

See also: #10557

Regards,

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 14, 2009

froc commented

It is still not clear, if Eclipse 3.5 , JUnit 4.5 (or 4.6) with Spring 2.5.6. can work.

Will there be a patch to support it?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Sep 14, 2009

Sam Brannen commented

Hi froc,

The Spring TestContext Framework in Spring 2.5.6 only works with JUnit 4.4. There unfortunately will not be a patch to support JUnit 4.5 plus with the Spring 2.5.x branch.

On the other hand, Spring 3.0 supports JUnit 4.5, 4.6, and 4.7.

That may not be the answer you hoped for, but I hope it clarifies the situation for you.

Regards,

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 9, 2009

Werner Guttmann commented

Well, the 2.5 branch entered strict maintenance mode last week. While we are in principle still able to support new versions of third-party dependencies, we can't raise the minimum level unless the previously supported version was pre-release software. Unfortunately it seems that supporting JUnit 4.5 here means requiring JUnit 4.5+; we can't do that before Spring 3.0 since all sorts of present build and development environments have JUnit 4.4 baked into them. It's unpleasant but not our fault - there was no better way of doing the test context framework against the hard-to-extend JUnit 4.4.

Whilst I understand the main argument made here, this is getting a bit unpleasant now with the release of JUnit 4.7, as basically (given that Spring 3.0 GA has not been made available yet and Spring 2.5.X will not be changed anymore) we are not in a position anymore to simplify (and hence increase the test code quality of ) our test cases based upon the recent additions to JUnit 4.7 (such as new ''expected'' parameter on {@Test}, etc.).

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 9, 2009

Juergen Hoeller commented

Werner, Spring 3.0 GA is now scheduled for Monday Dec 14 (i.e. in four days); it is literally around the corner. Also, using last week's 3.0 RC3 for the time being is going to ensure a smooth upgrade path to GA, since we are sorting out very specific bugs only at this point. So 3.0 RC3 is a fine release and very recommendable for development purposes already; I just wouldn't go to production with it yet.

With respect to using a brand-new JUnit version with older versions of Spring: Fundamentally, there is no reason to keep holding on to Spring 2.5 when upgrading other parts of your stack. Take JUnit, or Tiles, or JRuby - all of which we support in new versions now in Spring 3.0 that did not work with Spring 2.5. All of those libs require Java 5 anyway, so the Java 5+ requirement in Spring 3 shouldn't be a showstopper for anyone here.

We are trying to be forward compatible as far possible but well, if JUnit breaks its runner contract from 4.4 to 4.5 and Spring 2.5 only had JUnit 4.4 to work against at the time, there is not much we can do other than catch up with the latest JUnit release in the latest generation of Spring. In particular sine Spring 2.5 has to remain compatible with JUnit 4.4 for support reasons: i.e . for people who stick with their original stack from back in 2007...

In summary, please give Spring 3.0 RC3 a try and let us know whether its JUnit 4.7 support works for your purposes :-)

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 10, 2009

Werner Guttmann commented

Thanks, Jürgen, for letting me know about the immediate release date for 3.0. This should ease our pain substantially.

And we will definitely give things a try re: JUnit 4.7, etc.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 15, 2009

Dennis Kieselhorst commented

3.0 GA isn't released yet, is it?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Dec 15, 2009

Sam Brannen commented

Dennis, 3.0 GA is tentatively scheduled to be released... today! ;)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 2, 2010

Neeme Praks commented

How about creating a separate artifact for the 2.5 branch with Junit 4.5+ support?
That would mean that existing users will not be affected and other users who need Junit 4.5+ can declare a different dependency (e.g. org.springframework:spring-test-junit45 or something along those lines).

Probably you won't take that route anymore, but still, it's an idea, at least for the future. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.