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

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

Closed
johanhaleby opened this issue Jul 23, 2015 · 13 comments
Closed

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

johanhaleby opened this issue Jul 23, 2015 · 13 comments

Comments

@johanhaleby
Copy link
Collaborator

From andrei.i...@gmail.com on October 08, 2009 10:54:32

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: http://code.google.com/p/powermock/issues/detail?id=179

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 08, 2009 01:58:33

Test file

Attachment: RuleTest.java

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 08, 2009 23:11:20

Thanks, I'll check it out asap.

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 02:09:52

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!

Status: Started
Labels: -Priority-Medium Priority-Critical Milestone-Release1.4

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 02:48:05

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.

Status: Fixed

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 12, 2009 03:56:02

I have some problems building the project...
Can you give me a binary snapshot please?

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 04:04:42

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.

Attachment: powermock-module-junit4-1.4-SNAPSHOT.jar powermock-module-junit4-1.4-SNAPSHOT-sources.jar powermock-module-junit4-common-1.4-SNAPSHOT.jar powermock-module-junit4-common-1.4-SNAPSHOT-sources.jar

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 12, 2009 04:18:19

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-utils-1.5.8.jar
urls[2] =
file:/C:/Users/me/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar
urls[3] =
file:/C:/Users/me/.m2/repository/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar
urls[4] =
file:/C:/Users/me/.m2/repository/org/apache/maven/maven-archiver/2.3/maven-archiver-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/maven-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-core-1.0.jar
urls[9] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-i18n/1.0-beta-7/plexus-i18n-1.0-beta-7.jar
urls[10] =
file:/C:/Users/me/.m2/repository/org/codehaus/plexus/plexus-velocity/1.1.7/plexus-velocity-1.1.7.jar
urls[11] =
file:/C:/Users/me/.m2/repository/org/apache/velocity/velocity/1.5/velocity-1.5.jar
urls[12] =
file:/C:/Users/me/.m2/repository/commons-collections/commons-collections/3.2/commons-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/doxia-module-apt-1.0.jar
urls[17] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-fml/1.0/doxia-module-fml-1.0.jar
urls[18] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-xdoc/1.0/doxia-module-xdoc-1.0.jar
urls[19] =
file:/C:/Users/me/.m2/repository/org/apache/maven/doxia/doxia-module-xhtml/1.0/doxia-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\ExpectNewOfFinalSystemClassDemo.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

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 12, 2009 04:40:11

It seems to work now, thank you :-)

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 04:45:59

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.

Status: Started

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 12, 2009 04:55:23

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

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 05:06:07

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.

@johanhaleby
Copy link
Collaborator Author

From andrei.i...@gmail.com on October 12, 2009 05:30:45

The test with the rule seems to work after the update(rev 1047)

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on October 12, 2009 05:40:22

Thanks a lot for your help Andrei, we really appreciate it!

Status: Verified

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

No branches or pull requests

1 participant