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

JUnit suppresses AssertionError.getCause() #375

Closed
cowwoc opened this issue Jan 29, 2012 · 1 comment
Closed

JUnit suppresses AssertionError.getCause() #375

cowwoc opened this issue Jan 29, 2012 · 1 comment

Comments

@cowwoc
Copy link

cowwoc commented Jan 29, 2012

I am using JUnit 4.10.

If a test method invokes code that throws AssertionError (that is, not the test method itself, but the code it is exercising) then JUnit replaces it with an AssertionFailedError exception that does not include the "cause" of the original exception. I need this information to track the problem to its source!

Here is an example of what I get from JUnit:

Testcase: insertDependency(org.pill.repository.local.LocalRepositoryTest): FAILED
java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.String
junit.framework.AssertionFailedError: java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.String
at org.pill.repository.local.LocalRepository.insertRelease(LocalRepository.java:256)
at org.pill.ReleaseBuilder.build(ReleaseBuilder.java:83)
at org.pill.repository.local.LocalRepositoryTest.insertDependency(LocalRepositoryTest.java:161)

Here is what I get if I explicitly catch the AssertionError and printStackTrace() in my test method:

java.lang.AssertionError: java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.String
at org.pill.repository.local.LocalRepository.insertRelease(LocalRepository.java:256)
at org.pill.ReleaseBuilder.build(ReleaseBuilder.java:83)
at org.pill.repository.local.LocalRepositoryTest.insertDependency(LocalRepositoryTest.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
Caused by: java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.String
at org.pill.repository.local.LocalRepository.getRelease(LocalRepository.java:782)
at org.pill.repository.local.LocalRepository.access$500(LocalRepository.java:44)
at org.pill.repository.local.LocalRepository$InsertRelease.call(LocalRepository.java:375)
at org.pill.repository.local.LocalRepository$InsertRelease.call(LocalRepository.java:263)
at org.pill.repository.local.RequestInjector$1.call(RequestInjector.java:50)
at com.google.inject.servlet.ServletScopes$4.call(ServletScopes.java:251)
at org.pill.repository.local.LocalRepository.insertRelease(LocalRepository.java:233)
... 25 more

@dsaff
Copy link
Member

dsaff commented Oct 10, 2013

Sorry for the age of this request. This appears to be a situation where ant is trying to run a JUnit 4 test as if it were a JUnit 3 test. Are you still having this problem?

@kcooney kcooney closed this as completed Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants