Thoppan / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Powermock JUnit runner fails with JUnit 4.9+ TestRules #344

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by jrh...@gmail.com on 26 Aug 2011 at 1:56

Attachments:

GoogleCodeExporter commented 9 years ago
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)

Original comment by jrh...@gmail.com on 26 Aug 2011 at 1:57

GoogleCodeExporter commented 9 years ago
I suspected this. Thanks for reporting.

Original comment by johan.ha...@gmail.com on 30 Aug 2011 at 6:40

GoogleCodeExporter commented 9 years ago
java.lang.ClassCastException: org.junit.rules.TemporaryFolder cannot be cast to 
org.junit.rules.MethodRule

Original comment by johan.ha...@gmail.com on 13 Oct 2011 at 6:56

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 7 Feb 2012 at 10:27

GoogleCodeExporter commented 9 years ago
Issue 365 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 7 Feb 2012 at 10:29

GoogleCodeExporter commented 9 years ago
Issue 384 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 10 May 2012 at 7:22

GoogleCodeExporter commented 9 years ago
Please verify if the fix works by build powermock from trunk.

Original comment by johan.ha...@gmail.com on 29 Jul 2012 at 12:11

GoogleCodeExporter commented 9 years ago
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"

Original comment by jrh...@gmail.com on 30 Jul 2012 at 1:26

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

Original comment by johan.ha...@gmail.com on 30 Jul 2012 at 1:39

GoogleCodeExporter commented 9 years ago
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.

Original comment by jrh...@gmail.com on 30 Jul 2012 at 2:41

Attachments:

GoogleCodeExporter commented 9 years ago
Great, thanks for trying out it!

Original comment by johan.ha...@gmail.com on 30 Jul 2012 at 2:55

GoogleCodeExporter commented 9 years ago
Is there an estimated date for a release with this fix? It will be very welcome 
;)

Original comment by simioni....@gmail.com on 21 Sep 2012 at 9:49

GoogleCodeExporter commented 9 years ago
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?

Original comment by jrh...@gmail.com on 16 Oct 2012 at 4:09

GoogleCodeExporter commented 9 years ago
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.

Original comment by johan.ha...@gmail.com on 16 Oct 2012 at 4:27

GoogleCodeExporter commented 9 years ago
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?

Original comment by papp.robert.s on 22 Oct 2012 at 11:02

GoogleCodeExporter commented 9 years ago
https://issues.jboss.org/browse/JASSIST-160?focusedCommentId=12727919&page=com.a
tlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12727919

Original comment by andrei.i...@gmail.com on 22 Oct 2012 at 11:08