我有,我想验证的方法被称为具有给定参数的测试:春天引导和验证的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吗?