Using JUnit 4.7 Rules with PowerMockRunner

153 views
Skip to first unread message

Andrew

unread,
Oct 19, 2009, 8:40:03 AM10/19/09
to PowerMock
Hi,

I've recently tried to use a combination of the ExpectedException
runner with PowerMockRunner and it fails to work.

If I use:

@RunWith(PowerMockRunner.class)
public class SomeUnitTest {
@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testThis() {
thrown.expect(RuntimeException.class);

throw new RuntimeException();
}
}

It fails - however if I run it using the standard JUnit runner it
works. I have some vague that this is because you only can have one
runner but is there a way to extend JUnit's runner so we can inherit
things like Rules?

Johan Haleby

unread,
Oct 19, 2009, 9:46:41 AM10/19/09
to powe...@googlegroups.com
Are you using version 1.3? Previous to 1.3 PowerMock had no support for rules but unfortunately there's a critical bug in the 1.3 release that prevents rules to execute correctly so it's recommended not to use rules with PowerMockRunner in version 1.3. If you need to use rules right now you have to build PowerMock yourself from maven since the bug is fixed in the trunk. We'll release version 1.3.1 soon that fix this issue and some other minor bugs, probably some time this week.

Unfortunately there's no way to nest JUnit runners (afaik).

/Johan

liam.j.bennett

unread,
Oct 27, 2009, 3:37:15 PM10/27/09
to PowerMock
Hopefully this will be released very soon, because I have found @Rules
to be very useful.

Johan Haleby

unread,
Oct 27, 2009, 4:06:05 PM10/27/09
to powe...@googlegroups.com
Indeed they are :) I cannot promise any dates but hopefully soon (there's one more bug that I would like to solve first). If it's really urgent you could of course checkout the junit runner from trunk and build it yourself using "mvn install". That should work in the mean-time.

/Johan

liam.j.bennett

unread,
Oct 28, 2009, 5:33:54 AM10/28/09
to PowerMock
Thanks for you quick response. I have done a fresh checkout using the
latest maven 2.2.1 and I get the following error:
Your assistance would be greatly appreciated. Also, on a side note,
have you thought of moving this group to google wave?

/Liam


[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Internal error in the plugin manager executing goal
'org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile': Unable
to load the mojo 'org.apache.maven.plugins:maven-compiler-plugin:
2.0.2:compile' in the plugin 'org.apache.maven.plugins:maven-compiler-
plugin'. A required class is missin
g: org/codehaus/plexus/util/cli/CommandLineException
[INFO]
------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error
in the plugin manager executing goal 'org.apache.maven.plugins:maven-
compiler-plugin:2.0.2:compile': Unable to load the mojo
'org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile' in the
plugin 'org.apache.maven.plugins:m
aven-compiler-plugin'. A required class is missing: org/codehaus/
plexus/util/cli/CommandLineException
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals
(DefaultLifecycleExecutor.java:698)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle
(DefaultLifecycleExecutor.java:556)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal
(DefaultLifecycleExecutor.java:535)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures
(DefaultLifecycleExecutor.java:387)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments
(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute
(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:
328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:
138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main
(CompatibleMain.java:60)
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:585)
at org.codehaus.classworlds.Launcher.launchEnhanced
(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode
(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.PluginManagerException: Unable to
load the mojo 'org.apache.maven.plugins:maven-compiler-plugin:
2.0.2:compile' in the plugin 'org.apache.maven.plugins:maven-compiler-
plugin'. A required class is missing: org/codehaus/plexus/util/cli/
CommandLineException
at
org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo
(DefaultPluginManager.java:669)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo
(DefaultPluginManager.java:468)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals
(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Unable to lookup component
'org.apache.maven.plugin.Mojoorg.apache.maven.plugins:maven-compiler-
plugin:2.0.2:compile', it could not be started
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:339)
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:440)
at
org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo
(DefaultPluginManager.java:652)
... 19 more
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLifecycleException:
Error starting component
at
org.codehaus.plexus.component.manager.AbstractComponentManager.startComponentLifecycle
(AbstractComponentManager.java:109)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.createComponentInstance
(AbstractComponentManager.java:95)
at
org.codehaus.plexus.component.manager.PerLookupComponentManager.getComponent
(PerLookupComponentManager.java:48)
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:331)
... 21 more
Caused by:
org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException:
Error composing component
at
org.codehaus.plexus.personality.plexus.lifecycle.phase.CompositionPhase.execute
(CompositionPhase.java:33)
at org.codehaus.plexus.lifecycle.AbstractLifecycleHandler.start
(AbstractLifecycleHandler.java:101)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.startComponentLifecycle
(AbstractComponentManager.java:105)
... 24 more
Caused by:
org.codehaus.plexus.component.composition.CompositionException:
Composition failed of field compilerManager in object of type
org.apache.maven.plugin.CompilerMojo because the requirement
ComponentRequirement
{role='org.codehaus.plexus.compiler.manager.CompilerManager',
roleHint='null', fie
ldName='compilerManager'} was missing
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assignRequirementToField
(FieldComponentComposer.java:154)
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assembleComponent
(FieldComponentComposer.java:73)
at
org.codehaus.plexus.component.composition.DefaultComponentComposerManager.assembleComponent
(DefaultComponentComposerManager.java:68)
at org.codehaus.plexus.DefaultPlexusContainer.composeComponent
(DefaultPlexusContainer.java:1486)
at
org.codehaus.plexus.personality.plexus.lifecycle.phase.CompositionPhase.execute
(CompositionPhase.java:29)
... 26 more
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Unable to lookup component
'org.codehaus.plexus.compiler.manager.CompilerManager', it could not
be started
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:339)
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assignRequirementToField
(FieldComponentComposer.java:129)
... 30 more
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLifecycleException:
Error starting component
at
org.codehaus.plexus.component.manager.AbstractComponentManager.startComponentLifecycle
(AbstractComponentManager.java:109)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.createComponentInstance
(AbstractComponentManager.java:95)
at
org.codehaus.plexus.component.manager.ClassicSingletonComponentManager.getComponent
(ClassicSingletonComponentManager.java:92)
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:331)
... 31 more
Caused by:
org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException:
Error composing component
at
org.codehaus.plexus.personality.plexus.lifecycle.phase.CompositionPhase.execute
(CompositionPhase.java:33)
at org.codehaus.plexus.lifecycle.AbstractLifecycleHandler.start
(AbstractLifecycleHandler.java:101)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.startComponentLifecycle
(AbstractComponentManager.java:105)
... 34 more
Caused by:
org.codehaus.plexus.component.composition.CompositionException:
Composition failed of field compilers in object of type
org.codehaus.plexus.compiler.manager.DefaultCompilerManager because
the requirement ComponentRequirement
{role='org.codehaus.plexus.compiler.Compiler', roleHint='null', f
ieldName='compilers'} was missing
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assignRequirementToField
(FieldComponentComposer.java:154)
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assembleComponent
(FieldComponentComposer.java:73)
at
org.codehaus.plexus.component.composition.DefaultComponentComposerManager.assembleComponent
(DefaultComponentComposerManager.java:68)
at org.codehaus.plexus.DefaultPlexusContainer.composeComponent
(DefaultPlexusContainer.java:1486)
at
org.codehaus.plexus.personality.plexus.lifecycle.phase.CompositionPhase.execute
(CompositionPhase.java:29)
... 36 more
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Unable to lookup component
'org.codehaus.plexus.compiler.Compilerjavac', it could not be created
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:335)
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:440)
at org.codehaus.plexus.DefaultPlexusContainer.lookupMap
(DefaultPlexusContainer.java:390)
at
org.codehaus.plexus.component.composition.FieldComponentComposer.assignRequirementToField
(FieldComponentComposer.java:103)
... 40 more
Caused by:
org.codehaus.plexus.component.factory.ComponentInstantiationException:
Could not instanciate component: role:
'org.codehaus.plexus.compiler.Compiler', implementation:
'org.codehaus.plexus.compiler.javac.JavacCompiler', role hint: 'javac'
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.makeException
(JavaComponentFactory.java:77)
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.newInstance
(JavaComponentFactory.java:62)
at
org.codehaus.plexus.DefaultPlexusContainer.createComponentInstance
(DefaultPlexusContainer.java:1464)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.createComponentInstance
(AbstractComponentManager.java:93)
at
org.codehaus.plexus.component.manager.ClassicSingletonComponentManager.getComponent
(ClassicSingletonComponentManager.java:92)
at org.codehaus.plexus.DefaultPlexusContainer.lookup
(DefaultPlexusContainer.java:331)
... 43 more
Caused by: java.lang.NoClassDefFoundError: org/codehaus/plexus/util/
cli/CommandLineException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:
2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.newInstance
(JavaComponentFactory.java:44)
... 47 more
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 10 seconds

On Oct 27, 8:06 pm, Johan Haleby <johan.hal...@gmail.com> wrote:
> Indeed they are :) I cannot promise any dates but hopefully soon (there's
> one more bug that I would like to solve first). If it's really urgent you
> could of course checkout the junit runner from trunk and build it yourself
> using "mvn install". That should work in the mean-time.
>
> /Johan
>

Johan Haleby

unread,
Oct 28, 2009, 6:03:31 AM10/28/09
to powe...@googlegroups.com
I've heard other people reporting this before. I'm still using maven 2.0.9 and it seems to be working there. We need to fix this! If you have any idea what's causing this please let us know. Perhaps we just need to point to some never versions of the the maven plugins.

Btw I'm in the middle of releasing PowerMock 1.3.1 right now so hopefully you can upgrade very soon. I'll send an announcement when it's done.

/Johan
Reply all
Reply to author
Forward
0 new messages