Search code examples
javaspock

Stubbing or mocking static methods in Java with Spock


Is it possible to mock static methods in java with spock? I know it is possible to mock static groovy methods but can't get this working for Java methods.


Solution

  • No. You need PowerMockito for that. Refactor the class or alternatively wrap the static call in a protected method and stub it out as a spy.