6

I've been coding tests in Junit4 with Spring, and I got this funny behavior:

If my tests are passing like this, everything is fine:

@Test public void truthTest(){ assertTrue(true); //Ok } 

But, if my test fails:

@Test public void truthTest(){ assertTrue(false); //ERROR } 

Then instead of a test failure I receive an ugly and cryptic stack trace, This is it:

http://pastie.org/429912

Sorry for this ugly dump, but its the only data I've got to explain the problem (I "pastied" it for readability)

I'm really puzzled, has anyone encountered this kind of problem before? Thanks in advance!

1

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

On a bit of a side note: (as of now), the solution is "If you are using 4.0-4.4, try 4.5. If you are using 4.5, try 4.0-4.4". I just had the same issue and I solved it by upgrading to 4.5.
1

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

Comments

0

What if you imported AssumptionViolatedException into your test class?

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

1 Comment

I've imported org.junit.internals.AssumptionViolatedException but it doesnt work either

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.