ahmaddarawshi / powermock

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

Tests are not ran when JUnit 4.7 rule is used #179

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem:
1. Create a JUnit test with a @Rule
2. Run the test and observe it executes(the test method only has contains a
System.out.println("test") statement
3. add @RunWith(PowerMockRunner.class) and rerun test

The expected output is `test`, but instead the console remains blank

I'm using powermock-1.3 full, junit-4.7 on Win Vista

Looking at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl,
on line 58, rule.apply() is called but the result is unused.

Suggested solution:

Statement statement = rule.apply(new Statement() {
    @Override
    public void evaluate() throws Throwable {
            executeTestInSuper(method, testInstance, test);
    }
}, new FrameworkMethod(method), testInstance);
statement.evaluate();

Original issue reported on code.google.com by andrei.i...@gmail.com on 8 Oct 2009 at 8:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Test file

Original comment by andrei.i...@gmail.com on 8 Oct 2009 at 8:58

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I'll check it out asap.

Original comment by johan.ha...@gmail.com on 9 Oct 2009 at 6:11

GoogleCodeExporter commented 9 years ago
I've verified this and it seem like rules didn't work at all. I thought they did
because my test passed but upon further investigation they passed because the 
test
was not executed at all!

I've fixed so that these most rules should work in trunk but rules dealing with
exceptions (such as ExpectedException) doesn't work. I tried to get it working 
but
failed. I need to look into this in more detail. 

Thanks for reporting this!

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 9:09

GoogleCodeExporter commented 9 years ago
I've now fixed so that rules works (including those that expects exceptions). 
Andrei,
could you please checkout the source from trunk and verify that this works. I 
think
we need to release a new version of the PowerMock JUnit Runner asap because 
this is a
critical bug so I would really like if you could verify that this works.

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 9:48

GoogleCodeExporter commented 9 years ago
I have some problems building the project...
Can you give me a binary snapshot please?

Original comment by andrei.i...@gmail.com on 12 Oct 2009 at 10:56

GoogleCodeExporter commented 9 years ago
What problems do you have? It should be buildable from the sources using mvn 
install?
You may need to increase the permgen size though, use export
MAVEN_OPTS="-XX:MaxPermSize=512m" before running mvn install.

I'll attach my snapshots of the runner anyways, thanks for your help so far. 

Ps: I hope these files are enough.

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 11:04

Attachments:

GoogleCodeExporter commented 9 years ago
well.. the build errors:

[INFO] ------------------------------------------------------------------------
[INFO] Building powermock
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] Preparing source:jar
[WARNING] Removing: jar from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] [source:jar {execution: attach-sources}]
-----------------------------------------------------
this realm = 
app0.child-container[org.apache.maven.plugins:maven-javadoc-plugin:2.6]
urls[0] =
file:/C:/Users/me/.m2/repository/org/apache/maven/plugins/maven-javadoc-plugin/2
.6/maven-javadoc-plugin-2.6.jar
urls[1] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-u
tils-1.5.8.jar
urls[2] =
file:/C:/Users/me/.m2/repository/commons-httpclient/commons-httpclient/3.1/commo
ns-httpclient-3.1.jar
urls[3] =
file:/C:/Users/me/.m2/repository/commons-logging/commons-logging/1.0.4/commons-l
ogging-1.0.4.jar
urls[4] =
file:/C:/Users/me/.m2/repository/org/apache/maven/maven-archiver/2.3/maven-archi
ver-2.3.jar
urls[5] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-9
/plexus-archiver-1.0-alpha-9.jar
urls[6] =
file:/C:/Users/me/.m2/repository/org/apache/maven/shared/maven-invoker/2.0.9/mav
en-invoker-2.0.9.jar
urls[7] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-site-renderer/1.0/
doxia-site-renderer-1.0.jar
urls[8] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-core/1.0/doxia-cor
e-1.0.jar
urls[9] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-i18n/1.0-beta-7/plex
us-i18n-1.0-beta-7.jar
urls[10] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-velocity/1.1.7/plexu
s-velocity-1.1.7.jar
urls[11] =
file:/C:/Users/me/.m2/repository/org/apache/velocity/velocity/1.5/velocity-1.5.j
ar
urls[12] =
file:/C:/Users/me/.m2/repository/commons-collections/commons-collections/3.2/com
mons-collections-3.2.jar
urls[13] =
file:/C:/Users/me/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.
jar
urls[14] = file:/C:/Users/me/.m2/repository/oro/oro/2.0.8/oro-2.0.8.jar
urls[15] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-decoration-model/1
.0/doxia-decoration-model-1.0.jar
urls[16] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-apt/1.0/dox
ia-module-apt-1.0.jar
urls[17] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-fml/1.0/dox
ia-module-fml-1.0.jar
urls[18] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-xdoc/1.0/do
xia-module-xdoc-1.0.jar
urls[19] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-xhtml/1.0/d
oxia-module-xhtml-1.0.jar
urls[20] =
file:/C:/Users/me/.m2/repository/commons-codec/commons-codec/1.2/commons-codec-1
.2.jar
urls[21] =
file:/C:/Users/me/.m2/repository/com/thoughtworks/qdox/qdox/1.9.2/qdox-1.9.2.jar
Number of imports: 10
import: org.codehaus.classworlds.Entry@a6c57a42
import: org.codehaus.classworlds.Entry@12f43f3b
import: org.codehaus.classworlds.Entry@20025374
import: org.codehaus.classworlds.Entry@f8e44ca4
import: org.codehaus.classworlds.Entry@92758522
import: org.codehaus.classworlds.Entry@ebf2705b
import: org.codehaus.classworlds.Entry@bb25e54
import: org.codehaus.classworlds.Entry@bece5185
import: org.codehaus.classworlds.Entry@3fee8e37
import: org.codehaus.classworlds.Entry@3fee19d8

this realm = plexus.core
urls[0] = 
file:/C:/kits/java/maven/apache-maven-2.2.1/bin/../lib/maven-2.2.1-uber.jar
Number of imports: 10
import: org.codehaus.classworlds.Entry@a6c57a42
import: org.codehaus.classworlds.Entry@12f43f3b
import: org.codehaus.classworlds.Entry@20025374
import: org.codehaus.classworlds.Entry@f8e44ca4
import: org.codehaus.classworlds.Entry@92758522
import: org.codehaus.classworlds.Entry@ebf2705b
import: org.codehaus.classworlds.Entry@bb25e54
import: org.codehaus.classworlds.Entry@bece5185
import: org.codehaus.classworlds.Entry@3fee8e37
import: org.codehaus.classworlds.Entry@3fee19d8
-----------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal
'org.apache.maven.plugins:maven-javadoc-plugin:2.6:jar': Unable to load the mojo
'org.apache.mave
n.plugins:maven-javadoc-plugin:2.6:jar' in the plugin
'org.apache.maven.plugins:maven-javadoc-plugin'. A required class is missing:
org/codehaus/plexus/comp
onents/io/fileselectors/FileInfo
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13 seconds
[INFO] Finished at: Mon Oct 12 14:10:47 EEST 2009
[INFO] Final Memory: 21M/47M
[INFO] ------------------------------------------------------------------------

I don't really understand why.. It also happens with maven 2.1.1

After commenting out maven-javadoc-plugin:

powermock\reflect\src\test\java\org\powermock\reflect\WhiteBoxTest.java:186:
unexpected type
found   : java.lang.Object
required: reference
        assertTrue(Whitebox.invokeMethod(new ClassWithUniquePrivateMethods(), 8.2d,
8.3d, null) instanceof Object);

Trying again, without tests:

powermock\tests\utils\src\main\java\samples\expectnew\ExpectNewOfFinalSystemClas
sDemo.java:22:
cannot find symbol
symbol  : method isEmpty()
location: class java.lang.String
        return myString.isEmpty();

After fixing this, I get:
powermock\modules\module-impl\junit4-legacy\src\main\java\org\powermock\modules\
junit4\legacy\internal\impl\testcas
eworkaround\PowerMockJUnit4LegacyTestMethodRunner.java:86: java.lang.Object 
cannot be
dereferenced
                if (TestCase.class.isAssignableFrom(Whitebox.getInternalState(this,
"fTest").getClass())) {

Using java 1.5

I will try with your builds

Original comment by andrei.i...@gmail.com on 12 Oct 2009 at 11:18

GoogleCodeExporter commented 9 years ago
It seems to work now, thank you :-)

Original comment by andrei.i...@gmail.com on 12 Oct 2009 at 11:40

GoogleCodeExporter commented 9 years ago
I see, thanks for pointing this out. I have no idea what's wrong with the 
javadoc
plugin, I'm using maven 2.0.9 and java6. You could try "mvn install
-Dmaven.javadoc.skip=true" instead of commenting out the plugin but it doesn't 
solve
the error I suppose. I'm fixing the isEmpty issue as we speak. I should probably
switch to Java5 when I'm developing as well :)

I've found a new error in the runner though, tests never fails on assertion 
errors
which is an even worse bug. I'm working on that right now. I'll upload new 
binaries
here when I've fixed it and I would be very glad if you could try it out again. 
Sorry
for all the hassle.

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 11:45

GoogleCodeExporter commented 9 years ago
There's no need for the binaries, it seems that even with these errors, the 
required
packages are still being built.
I still get the javadoc error with -Dmaven.javadoc.skip=true

Original comment by andrei.i...@gmail.com on 12 Oct 2009 at 11:55

GoogleCodeExporter commented 9 years ago
I think I've fixed the issues now (fingers crossed). So if you don't mind would 
you
please update from trunk and try again?

I'll also add your build issues to a new issue.

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 12:06

GoogleCodeExporter commented 9 years ago
The test with the rule seems to work after the update(rev 1047)

Original comment by andrei.i...@gmail.com on 12 Oct 2009 at 12:30

GoogleCodeExporter commented 9 years ago
Thanks a lot for your help Andrei, we really appreciate it!

Original comment by johan.ha...@gmail.com on 12 Oct 2009 at 12:40