Joe Klonowski Joe Klonowski -4 years ago 216
Java Question

no last call on a mock available happening only when calling testng via ant

My test stack is:


  • TestNG - Bolding this because I see @runWith recommended as the solution when that's JUnit only

  • EasyMock

  • PowerMock's MockStatic



I've got a test class that I've annotated with @PrepareForTest(StaticClass.class)

And then in my test I'm doing a very simple

PowerMock.mockStatic(StaticClass.class);
StaticClass.method(parameter);
expectLastCall().anyTimes();


I'm getting the standard "java.lang.IllegalStateException: no last call on a mock available" issue, but ONLY when running TestNG from ant, not when running from Eclipse. I believe my classpath includes all the necessary .jar files as PowerMock.mockStatic() is being called fine and all jars were added to the same classpath.

Any help is much appreciated.

Answer Source

The error ended up being with some incompatible versions of powermock and testng as well as not overwriting the object factory as mentioned here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download