0
如何在單元測試中模擬由Spring自動裝配的bean的List
。Mocking autowired @Resource List
到目前爲止,我無法達到我想要的結果。有沒有辦法做到這一點?
@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);
}
...
}
看來,Springockito應該做的伎倆,但它太麻煩了:)結束了嘲笑IsAliveEnabledComponent和手動添加列表。 –