如何List
在单元测试中模拟 Spring 自动装配的 bean。
到目前为止,我无法达到我想要的结果。有没有办法做到这一点?
@Component
public class CrmStatusChecker {
@Resource
private List<IsAliveEnabledComponent> components;
....
}
测试
@RunWith(MockitoJUnitRunner.class)
public class CrmStatusCheckerTest {
@Mock
private List<IsAliveEnabledComponent> isAliveComponents;
@InjectMocks
private final CrmStatusChecker crmStatus = new CrmStatusChecker();;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
...
}