How to test constructor of a class that has a @PostConstruct method using Spring?

后端 未结 4 2134
遇见更好的自我
遇见更好的自我 2021-02-18 13:12

If I have a class with a @PostConstruct method, how can I test its constructor and thus its @PostConstruct method using JUnit and Spring? I can\'t simply use new ClassName(param

4条回答
  •  梦如初夏
    2021-02-18 13:46

    @PostConstruct must be changing the state of the object. So, in JUnit test case, after getting the bean check the state of the object. If it is same as the state set by @PostConstruct, then the test is success.

提交回复
热议问题