简体   繁体   中英

Mocking spring beans in Munit

I am writing an MUnit test and would like to mock some of the beans used in my test but I have no idea how to inject them into the flow. Is this possible in MUnit?

I understand that you have a bean in your application and you want to change how it works for the purpose of the test, is this correct?

First thing to say here is, MUnit only mocks message processors. So top level elements such as configs or spring beans can't be mocked.

What you could do though is, have your spring beans defined in one file separated from your logic. When you run your tests you only import the file where you app logic is and provide the missing beans with your implementation.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM