相关疑难解决方法(0)

使用JUnit @Rule使用Mockito进行参数化测试?

这是从这个问题开始的:我被要求开始一个新问题.

问题是我对JUnit不够了解Rule,或者在这里发生了什么Runners等等,以Jeff Bowman提到的方式解决问题.

java junit rule mockito parameterized-tests

12
推荐指数
1
解决办法
1万
查看次数

在方法上具有 @Retryable 注释的模拟 Spring @Service 失败并出现 UnfinishedVerificationException

我将 Spring Boot1.4.0.RELEASEspring-boot-starter-batch,spring-boot-starter-aopspring-retry

我有一个 Spring 集成测试,其中有一个@Service在运行时被模拟的。我注意到,如果该类在其方法上@Service包含任何@Retryable注释,那么它似乎会干扰Mockito.verify(),我得到一个UnfinishedVerificationException. 我想这一定与什么有关spring-aop?如果我注释掉@Retryable中的所有注释,@Service则验证工作再次正常。

我创建了一个github 项目来演示这个问题。

它失败sample.batch.MockBatchTestWithRetryVerificationFailures.batchTest()validateMockitoUsage();

像这样的东西:

12:05:36.554 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - After test method: context [DefaultTestContext@5ec0a365 testClass = MockBatchTestWithRetryVerificationFailures, testInstance = sample.batch.MockBatchTestWithRetryVerificationFailures@5abca1e0, testMethod = batchTest@MockBatchTestWithRetryVerificationFailures, testException = org.mockito.exceptions.misusing.UnfinishedVerificationException: 
Missing method call for verify(mock) here:
-> at sample.batch.service.MyRetryService$$FastClassBySpringCGLIB$$7573ce2a.invoke(<generated>)

Example of correct verification:
    verify(mock).doSomething()
Run Code Online (Sandbox Code Playgroud)

不过,我有另一个类( ) ,它带有一个没有任何注释的sample.batch.MockBatchTestWithNoRetryWorking.batchTest()模拟类,并且验证工作正常。 …

spring spring-aop mockito spring-batch spring-retry

3
推荐指数
1
解决办法
3691
查看次数