praveen1503 / powermock

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

cannot set test expectations in @Before method with Powermock Rule and Spring Runner #406

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a test with SpringJUnit4ClassRunner and a PowerMockRule
2. add some expectations in @Before method
3. run test

example : 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-appContext.xml"})
@PrepareForTest(MyClass.class)
public class PowerMockRuleTest {
    @Rule
    public PowerMockRule powerMockRule = new PowerMockRule();

    @Before
    public void setUp(){
        PowerMock.mockStatic(MyClass.class);
        //following line throws an IllegalStateException
        EasyMock.expect(MyClass.someStaticMethod()).andReturn(0);
        PowerMock.replay(MyClass.class);

    }

    @Test
    public void dummy() {
        Assert.assertTrue(true);
    }
}

What is the expected output? What do you see instead?
expected : test should pass
actual : 
java.lang.IllegalStateException: no last call on a mock available
        at org.easymock.EasyMock.getControlForLastCall(EasyMock.java:520)
    at org.easymock.EasyMock.expect(EasyMock.java:498)
    at com.my.example.PowerMockRuleTest.setUp(PowerMockRuleTest.java:25)

What version of the product are you using? On what operating system?
JUnit 4.9
Easymock 3.1
Powermock 1.4.10
Spring 3.0.3.RELEASE

Please provide any additional information below.
The test passes if calls to mockStatic, expect and replay are done directly in 
the @Test method

Original issue reported on code.google.com by audrey.r...@gmail.com on 6 Nov 2012 at 5:06

GoogleCodeExporter commented 8 years ago
What rule are you using? Classloader based or agent based?

Original comment by johan.ha...@gmail.com on 29 Nov 2012 at 6:49

GoogleCodeExporter commented 8 years ago
I have the problem with the classloader based rule.

I just tried with the agent based one, and the test runs fine.

Original comment by audrey.r...@gmail.com on 3 Dec 2012 at 10:55

GoogleCodeExporter commented 8 years ago
Alright.

Original comment by johan.ha...@gmail.com on 3 Dec 2012 at 10:58