私は2つのステップの定義におけるキュウリ春Bootテストで@Spyオブジェクトできません

Antonio682:

私は春ブーツ2とキュウリのテストを実行している問題を抱えています。

私は2つのステップの定義を持っており、両方のclasesに私は、このクラスの1つのメソッドに渡される引数を捕獲しようとしているmockitoを持つオブジェクトをスパイしてみてください。

ポイントはキュウリが唯一の春のアプリケーションコンテキストコンフィギュレーションIすることができますので、それを構成するには、抽象クラスを作成し、私は、このクラスでの手順の定義の拡張1をしたしたことです。

@ActiveProfiles("INTEGRATION_TEST")
@SpringBootTest
@ContextConfiguration(classes = ServiceApplication.class)
@TestPropertySource(properties = 
      {"spring.config.location=classpath:application-test.yml"})
public abstract class BaseTestIntegration {}


@Ignore
public class OfferEventsGenerationStep extends BaseTestIntegration {

@Autowired private LoanOfferBatchController loanOfferBatchController;
@SpyBean private SendEventOfferServiceImpl sendEventService;
@Captor private ArgumentCaptor<CreateOfferToUserEvent> createOfferEventCaptor;
@Autowired private GenericWebApplicationContext context;
.........
 @Then("^events will be created$")
public void eventsWillBeCreated() throws Throwable {
    Mockito.verify(sendEventService, Mockito.times(5)).sendEvent(createOfferEventCaptor.capture());
 }
}


@Ignore
public class SecondEventsGenerationStep  {

@Autowired private LoanOfferBatchController loanOfferBatchController;
@SpyBean private SendEventSencondServiceImpl sendEventService;
@Captor private ArgumentCaptor<CreateOfferToUserEvent> createOfferEventCaptor;
@Autowired private GenericWebApplicationContext context;
.........
 @Then("^events will be created$")
public void eventsWillBeCreated() throws Throwable {
    Mockito.verify(sendEventService, Mockito.times(2)).sendEvent(createOfferEventCaptor.capture());
 }
}

sendEventServiceだけ他方はこの例外をスローBaseTestIntegrationクラスを拡張するクラスでスパイBeanとして認識されていることを除いて、すべてが罰金を動作します:

 org.mockito.exceptions.misusing.NotAMockException: 
 Argument passed to verify() is of type SendEventSencondServiceImpl and is not a mock!
mpkorstanje:

それは使用することはできません@MockBean@SpyBeanのでcucumber-spring豆にターンのステップの定義および使用されませんTestContextManager問題があるキュウリ、春の#1470でサポート@MockBeanは誰もがそれを取るしたい場合には、グラブのためにアップします。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=211313&siteId=1