Thoppan / powermock

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

PowerMock not running TestRules with JUnit 4.10 #365

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Create the following class:
@RunWith(Enclosed.class)
public class PowerMockTest {
    @RunWith(PowerMockRunner.class)
    public static class WithPowerMock {
        @Rule
        public final ExpectedException thrown = ExpectedException.none();

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

            throw new RuntimeException();
        }
    }

    public static class WithoutPowerMock {
        @Rule
        public final ExpectedException thrown = ExpectedException.none();

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

            throw new RuntimeException();
        }
    }

}

(Note this happens without the enclosure, that's simply being used for 
illustration.)

2. Run the class (I am running through Eclipse, though that shouldn't make a 
difference)

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

I'd expect both tests to pass, instead testWillFail() ends with an error 
because of the RuntimeException.

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

PowerMock 1.4.11 with Mockito 1.9.0 and JUnit 4.10.

Please provide any additional information below.

* Attempted changing the PowerMockRunner to a PowerMockRule, but this did not 
change that the TestRule was not being used.
* @Test(expected=RuntimeException.class) continues to work normally, however 
this doesn't apply to other test rules. 
* Adding the rules to @PowerMockIgnore (shot in the dark).
* Attempted it with other TestRules (specifically TestWatcher) and found the 
same result: the rule was not being used. 

Original issue reported on code.google.com by nachtr...@gmail.com on 26 Jan 2012 at 5:18

GoogleCodeExporter commented 9 years ago
This is a known issue and it's unfortunately hard to resolve. Either we need to 
create a new runner for JUnit 4.9+ or we need to extend the functionality of 
the current runner to use the new rules when JUnit 4.9+ is detected (MethodRule 
has been renamed TestRule).

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