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

Powermock JUnit runner fails with JUnit 4.9+ TestRules #364

Closed
johanhaleby opened this issue Jul 24, 2015 · 16 comments
Closed

Powermock JUnit runner fails with JUnit 4.9+ TestRules #364

johanhaleby opened this issue Jul 24, 2015 · 16 comments

Comments

@johanhaleby
Copy link
Collaborator

@johanhaleby johanhaleby commented Jul 24, 2015

From jrh...@gmail.com on August 26, 2011 15:56:58

What steps will reproduce the problem? 1. Run "mvn test" on the attached project and observe the build failure
2. Run "mvn test -Djunit.version=4.8.2" and observe that the build succeeds What is the expected output? What do you see instead? A passing build, and, instead, a build failure What version of the product are you using? On what operating system? 1.4.10, on Windows 7 x86 Please provide any additional information below. It looks like, with JUnit 4.9, they changed rules like ExpectedException to implement TestRule instead of MethodRule. The Powermock runner expects them to implement MethodRule and, as a result, a ClassCastException is thrown.

Attachment: junit-49-failure.zip

Original issue: http://code.google.com/p/powermock/issues/detail?id=344

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From jrh...@gmail.com on August 26, 2011 06:57:59

For posterity, this is the stacktrace I see during the build failure:


Test set: com.googlecode.powermock.kablooey.KablooeyTest

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.039 sec <<< FAILURE!
testKablooey(com.googlecode.powermock.kablooey.KablooeyTest) Time elapsed: 0.009 sec <<< ERROR!
java.lang.ClassCastException: org.junit.rules.ExpectedException
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:79)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on August 29, 2011 23:40:30

I suspected this. Thanks for reporting.

Status: Accepted
Labels: -Priority-Medium Priority-High

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on October 12, 2011 23:56:41

java.lang.ClassCastException: org.junit.rules.TemporaryFolder cannot be cast to org.junit.rules.MethodRule

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on February 07, 2012 02:27:03

Summary: Powermock JUnit runner fails with JUnit 4.9+ TestRules

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on February 07, 2012 02:29:37

Issue 365 has been merged into this issue.

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on May 10, 2012 00:22:17

Issue 384 has been merged into this issue.

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on July 29, 2012 05:11:33

Please verify if the fix works by build powermock from trunk.

Status: Fixed

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From jrh...@gmail.com on July 30, 2012 06:26:03

Is there a particular way I should try building the project? I tried doing a "mvn clean install" from the root of "/trunk" after a checkout, and got this error:

[INFO] Compilation failure
C:\Temp\trunk\reflect\src\test\java\org\powermock\reflect\WhiteBoxTest.java:[175,48] unexpected type
found : java.lang.Object
required: reference

This is what I'm trying to build with:

Apache Maven 2.2.1 ( r801777 ; 2009-08-06 14:16:01-0500)
Java version: 1.5.0_22
Java home: C:\Program Files (x86)\Java\jdk1.5.0_22\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "x86" Family: "windows"

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on July 30, 2012 06:39:14

I'm building with Maven 3 and Java 6 but it ought to work with Java 5 as well. Don't know about maven2.

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From jrh...@gmail.com on July 30, 2012 07:41:43

Gotcha. I used Maven 2 + Java 5 because of the maven-compiler-plugin configuration in the root POM. It successfully built with Maven 3 + Java 6, and the change seems to work dandily with JUnit 4.10 and 4.8.2. I'm attaching the project I used to verify the changes.

Attachment: powermock-junit-validation.zip

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on July 30, 2012 07:55:49

Great, thanks for trying out it!

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From simioni....@gmail.com on September 21, 2012 02:49:42

Is there an estimated date for a release with this fix? It will be very welcome ;)

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From jrh...@gmail.com on October 16, 2012 09:09:29

This is marked as closed, but I'm still seeing it in 1.4.12. Was this released with any specific version of powermock yet?

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on October 16, 2012 09:27:37

It hasn't been released yet. It's only available in trunk atm. I'm waiting for a new release of Javassist before I release a new version.

@johanhaleby
Copy link
Collaborator Author

@johanhaleby johanhaleby commented Jul 24, 2015

From papp.robert.s on October 22, 2012 04:02:52

And when will that be? The last activity I found was this March, so it doesn't seem too frequent. Can't you just do a 1.4.13 patch release, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.