Skip to content

How to use spock to mock static Method #1757

Answered by Vampire
MagicWang0907 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@MagicWang0907
Comment options

Answer selected by AndreasTu
Comment options

You must be logged in to vote
1 reply
@MagicWang0907
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants