on-internet
← Community

How to mock static method while using Spring Boot?

Stack Overflow ·

I need to mock a static method. I know of two tools to help do this: PowerMockito and JMockit, both of which require usage of the @RunWith annotation. However, I've already used @RunWith for SpringRunner to set up some @Autowired dependencies, and it seems you can't use @RunWith twice. I see that PowerMockito has a PowerMockRunnerDelegate, which looks promising. But for various reasons, I'm stuck using JMockit for now. Is there a JMockit equivalent for this? I essentially need to mock a static method and set up @Autowired dependencies for my test at the same time.

Comments

Sign in or sign up to comment and upvote.

No comments yet.