Is it possible to monkey patch in Java?

后端 未结 9 550
有刺的猬
有刺的猬 2020-12-09 16:40

I don\'t want to discuss the merits of this approach, just if it is possible. I believe the answer to be \"no\". But maybe someone will surprise me!

Imagine you have

9条回答
  •  心在旅途
    2020-12-09 17:06

    You can try using tools like PowerMock/Mockito. If you can mock in tests, you can mock in production too.

    However these tools are not really designed to be used that way, so you'll have to prepare the environment yourself and won't be able to use the JUnit runners like you do in tests...

提交回复
热议问题