rafael81 / powermock

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

Static method mocking is passing when we run as individual test cases but fails in running all test cases #450

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am facing issues with some test cases failures having static mocks.
If I run the file as individual test case in TestNG. Then it works fine.
But if I run all test cases in the project then it fails. whatever it is TestNG 
or maven test.

What steps will reproduce the problem?
1. pom.xml, i mentioned

<dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-easymock</artifactId>
            <version>1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.5</version>
        </dependency>

2. Class i already attached it.

error is as below:

testDefaultOptInWowoValue(com.paypal.merchant.onboarding.controller.TestHawkWowo
)  Time elapsed: 0.038 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testDefaultOptInWowoValue(TestHawkWowo.java:104)

testDefaultWhitelistWowoValue(com.paypal.merchant.onboarding.controller.TestHawk
Wowo)  Time elapsed: 0.002 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testDefaultWhitelistWowoValue(TestHawkWowo.java:56)

testOptinWowoOff(com.paypal.merchant.onboarding.controller.TestHawkWowo)  Time 
elapsed: 0.002 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testOptinWowoOff(TestHawkWowo.java:72)

testOptinWowoOn(com.paypal.merchant.onboarding.controller.TestHawkWowo)  Time 
elapsed: 0.001 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testOptinWowoOn(TestHawkWowo.java:88)

testWhitelistWowoOff(com.paypal.merchant.onboarding.controller.TestHawkWowo)  
Time elapsed: 0.002 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testWhitelistWowoOff(TestHawkWowo.java:24)

testWhitelistWowoOn(com.paypal.merchant.onboarding.controller.TestHawkWowo)  
Time elapsed: 0.002 sec  <<< FAILURE!
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.paypal.merchant.onboarding.controller.TestHawkWowo.testWhitelistWowoOn(TestHawkWowo.java:40)

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

it should pass as the way it is passing as individual.

What version of the product are you using? On what operating system?
1.5 , windows 7 Enterprise

Please provide any additional information below.

I have tried PowerMockito too. But result is little bit different. Passing in 
running as individual testcases. Failing when i run all test cases.

In case of powermockito at least it is not throwing exception at declaration 
time i.e.

try {
            PowerMockito.doReturn(appCtx).when(WebFrameworkContext.class,"getAppContext");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

First test cases is passing but in another test cases it is failing because 
getAppContext is returning as null.

Attached both classes. Using with PowerMock and with PowerMockito.
And also a single test case implemented as mentioned in this website.

I am new to Mocking. If i am doing mistake then plzzz let me know. 

Original issue reported on code.google.com by mritunja...@gmail.com on 19 Jun 2013 at 5:09

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Attaching a file which is using power mock static import. Stack trace is 
mentioned in previous comment.

Original comment by mritunja...@gmail.com on 19 Jun 2013 at 5:21

Attachments: