how8586 / powermock

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

Incompatibility with SpringFramework : runner conflict #156

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using Dependency injection (@Autowired or extends
JunitSpringDependencyInjection...) in my Junit Test
2. While using @Runwith(PowermockRunner.java)

What is the expected output? What do you see instead?

ClassCastException: An awesome Can't cast "myclass.java" to "myclass.java"

What version of the product are you using? On what operating system?

Last one  : 1.2.5 with eclipse on Ubuntu 9.04

Please provide any additional information below.

Already triied to ignore involved Paths with PowerMock ignore....

Original issue reported on code.google.com by souquier...@gmail.com on 11 Sep 2009 at 7:28

GoogleCodeExporter commented 9 years ago
PowerMock's main intention is to be used in unit tests where you want to 
isolate the
code under test from an environment. What you're probably doing is an 
integration
test. Never the less it would be nice to get it working so I'll add it as an
enhancement request

Original comment by johan.ha...@gmail.com on 11 Sep 2009 at 10:03

GoogleCodeExporter commented 9 years ago
It's not an integration test, the class i want to test is a Spring bean in our
application.

I manage to resolve this by using Default constructor and set manually all 
necessary
properties.

Yes, it would be an enhancement, less work for the same result, I suppose it 
requires
a Spécifique runner "Spring compatible". Like @RunWith( 
SpringJUnit4ClassRunner.class
), allowing the use of injection. But it's a quite complicated for me when it 
comes
to JVM consideration...

Original comment by souquier...@gmail.com on 11 Sep 2009 at 3:32

GoogleCodeExporter commented 9 years ago
Hmm.. Could you create an example that demonstrates the issue?

Original comment by johan.ha...@gmail.com on 17 Mar 2010 at 7:22

GoogleCodeExporter commented 9 years ago
Is this enhancement done?
I intend to use PowerMockito's static mocking capability in integration tests 
ran
with SpringJunit4ClassRunner...

Original comment by eva.mukh...@gmail.com on 26 May 2010 at 7:49

GoogleCodeExporter commented 9 years ago
Try the PowerMockRule, that's the only viable option right now that I can think 
of.

Original comment by johan.ha...@gmail.com on 26 May 2010 at 8:14

GoogleCodeExporter commented 9 years ago
There are some really odd issues with running Spring Integration tests and 
PowerMock.
I'm using TestNG with a suite.xml file and just having PowerMock scanned in the 
classpath is doing something odd.

Original comment by samueldo...@gmail.com on 4 Oct 2010 at 8:28

GoogleCodeExporter commented 9 years ago
What do you mean by "just having PowerMock scanned ..."?

Are you using the rule?

Original comment by johan.ha...@gmail.com on 5 Oct 2010 at 10:42

GoogleCodeExporter commented 9 years ago
I probably run into the same issue, using spring's runner with PowerMockRule.

I want to create a static mock for slf4j LoggerFactory in a spring test, and I 
get "cannot subclass final class LoggerFactory".

If I remove the spring runner and use the PowerMock runner instead of the rule, 
the mock is created properly.

Original comment by dietrich...@gmail.com on 15 Nov 2010 at 6:40

GoogleCodeExporter commented 9 years ago
We have plans to make a second version of the PowerMock rule that uses e.g. 
XStream as deep-cloner instead of in-memory Objenesis state cloning which 
unfortunately is not very stable. I'm not sure if it'll solve your problem 
though, it could be that you may need to depend on the @PowerMockIgnore 
annotation...

Original comment by johan.ha...@gmail.com on 15 Nov 2010 at 7:31

GoogleCodeExporter commented 9 years ago
Thank you for your answer. What would I have to ignore then? 

Original comment by dietrich...@gmail.com on 15 Nov 2010 at 3:32

GoogleCodeExporter commented 9 years ago
I've recently created a new project called powermock-module-junit4-agent which 
bootstraps using a javaagent instead of classloaders. Please help us by 
checking out PowerMock from trunk and try if the new project works for you. 
Depend on:

<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule-agent</artifactId>
<version>1.4.9-SNAPSHOT</version>

in Maven. Then you use the @PowerMockRule as usually: 

@Rule
public PowerMockRule powermock = new PowerMockRule();

Original comment by johan.ha...@gmail.com on 10 Apr 2011 at 1:00

GoogleCodeExporter commented 9 years ago
I'm really hope this issue will be fixed on next release, please.

Original comment by keanu.p...@gmail.com on 6 Jul 2012 at 5:31