How to use spock to mock static Method #1757
-
The latest version no longer exists at org.spockFramework.runtime.sputnik, so how to mock static classes without Sputnik? i wanna an example |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Nothing changed regarding mocking of static methods. |
Beta Was this translation helpful? Give feedback.
-
As a note I am currently working on PRs in spock-core to allow static mocking (with help of Mockito) in the future. |
Beta Was this translation helpful? Give feedback.
Nothing changed regarding mocking of static methods.
The built-in mocking of Spock does not allow it for Java mocks.
If your code you test is written in Groovy, you can use a global Groovy mock to mock static methods like documented.
If you need to mock static methods in Java code, you need to use some other facility outside Spock currently.
But in most cases it would be preferable to rewrite the code under test to not need mocking static method calls.