我有,我想驗證的方法被稱爲具有給定參數的測試:春天引導和驗證的Mockito總是正確
@Autowired
private Client client;
@Autowired
private OtherClient otherClient;
@Test
public void test() {
client.push();
Mockito.verify(otherClient).publishReset(
Mockito.anyString(),
Mockito.argThat(l -> l.size() == 3)
);
}
問題是,Mockito.verify
並沒有失敗可言,我可以代替l -> l.size() == 3
與任何其他大小的匹配和給定的測試將始終通過。驗證如何能夠始終傳遞我傳遞給arg的所有內容?
全部下面的例子:
@EnableConfigurationProperties
@TestExecutionListeners(listeners = {
DirtiesContextTestExecutionListener.class,
DirtiesContextBeforeModesTestExecutionListener.class,
ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
MockitoTestExecutionListener.class,
TransactionalTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ContextConfiguration(
loader = SpringBootContextLoader.class,
classes = {MyApp.class, IntegrationTestContext.class})
@RunWith(SpringRunner.class)
public class FooIT {
@Autowired
private Client client;
@Autowired
private OtherClient otherClient;
@Test
public void test() {
client.push();
Mockito.verify(otherClient).publishReset(
Mockito.anyString(),
Mockito.argThat(l -> l.size() == 3)
);
}
}
和一個配置類:
@Configuration
@MockBeans({
@MockBean(OtherClient.class),
})
public class IntegrationTestContext {
}
有什麼,我做錯了嗎?莫名其妙地干擾了mockito嗎?