Mock static method with GroovyMock or similar in Spock

前端 未结 3 1651
误落风尘
误落风尘 2020-12-10 12:07

First-timer here, apologies if I\'ve missed anything. I\'m hoping to get around a call to a static method using Spock. Feedback would be great

With groovy mocks, I

3条回答
  •  暖寄归人
    2020-12-10 12:57

    The way I've gotten around static methods in Groovy/Spock is by creating proxy classes that are substituted out in the actual code. These proxy classes simply return the static method that you need. You would just pass in the proxy classes to the constructor of the class you're testing.

    Thus, when you write your tests, you'd reach out to the proxy class (that will then return the static method) and you should be able to test that way.

提交回复
热议问题