My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 293: PM 1.4.6 does err's out mocking statics and private functions, or is inconsistent in mocking them
6 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----

Sign in to add a comment
Reported by, Nov 17, 2010
Using Java 6, TestNG 5.14.2, EasyMock 3 and PM1.4.6, cannot get @PrepareForTest and subsequent mocking of private or static methods to succeed.

Mocking err's out during setting the mocks expectations.

The given tests should all work per the PowerMock documentation, though all four tests fail in Eclipse 3.6 and only one works in Maven. Test are performed with/without extending PowerMockTestCase. 

Errors occur setting expectations deeper in EasyMock. Example stack trace below:

FAILED: testGetSIAGood
java.lang.IllegalStateException: no last call on a mock available
	at org.easymock.EasyMock.getControlForLastCall(
	at org.easymock.EasyMock.expectLastCall(
	at org.powermock.api.easymock.PowerMock.doExpectPrivate(
	at org.powermock.api.easymock.PowerMock.expectPrivate(
	at org.powermock.api.easymock.PowerMock.expectPrivate(
	at org.powermock.api.easymock.PowerMock.expectPrivate(
	at IAXPMUCTest.testGetSIAGood(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.testng.internal.MethodInvocationHelper.invokeMethod(
	at org.testng.internal.Invoker.invokeMethod(
	at org.testng.internal.Invoker.invokeTestMethod(
	at org.testng.internal.Invoker.invokeTestMethods(
	at org.testng.internal.TestMethodWorker.invokeTestMethods(
	at org.testng.TestRunner.runWorkers(
	at org.testng.TestRunner.privateRun(
	at org.testng.SuiteRunner.runTest(
	at org.testng.SuiteRunner.runSequentially(
	at org.testng.SuiteRunner.privateRun(
	at org.testng.SuiteRunnerWorker.runSuite(
	at org.testng.TestNG.runSuitesSequentially(
	at org.testng.TestNG.runSuitesLocally(
	at org.testng.remote.RemoteTestNG.initAndRun(
	at org.testng.remote.RemoteTestNG.main(

Attached is a zip of the Maven project.


4.6 KB   Download
Nov 17, 2010
Tried updating the SetUp to use staticMock, with the same result as above. The code would read:

    public void setUp() throws UnknownHostException {
        addr = InetAddress.getLocalHost();
        uhe = new UnknownHostException("Dummy UHE");
        classUnderTest =
            PowerMock.createPartialMock(IAX.class, "getLocalHost");
        PowerMock.mockStaticPartial(IAX.class, "getStaticLocalHost");
Dec 12, 2010
Somebody should look into this issue
Can anyone suggest a workaround?
Sign in to add a comment

Powered by Google Project Hosting