dimanche 17 janvier 2021

given method in before method runs twice. capture null for first and string argument for second time

I initialize given method in a setup method for running before other methods. I have only one test method and if I run this method, the setup method calls and then test method runs and there's no problem.

But when I run the test class instead of the method, I get 2 tests run. one test gets correct argument and passed but another test that runs first gives the null argument and failed.

    @Test
    @BeforeEach
    void setup(){
        given(addressService.findByEmailContaining(stringArgumentCaptor.capture())).willAnswer(invocation  -> {
.
.
.
}

    @Test
    void testArgumentSearch(){
        .
        .
        String searchAdress = controller.searchAddressForTest(address, model);
        .
        .
}

Aucun commentaire:

Enregistrer un commentaire