【发布时间】:2018-10-01 18:37:11
【问题描述】:
我有两个豆子:
@Component
public class StudentServices {
// ... member variables, etc.
@Lookup
public SchoolNotification getNotification() {
return null;
}
// ... getters and setters
}
还有第二个豆子:
@Component
@Scope("prototype")
public class SchoolNotification {
// ... prototype-scoped state
}
我需要帮助来为 StudentServices 编写一个单元测试,以某种方式模拟 SchoolNotification。
Mockito.mock 不起作用,因为这两个 bean 具有不同的范围,并且每次执行 StudentServices.getNotification() 时,spring 上下文都会提供一个新的 SchoolNotification 实例。
任何帮助将不胜感激!
【问题讨论】:
标签: spring unit-testing spring-boot mockito