lundi 28 octobre 2019

Serialisation issue with spring-boot controller testing

I have my controller test set up like this:

@ExtendWith(SpringExtension.class)
@WebAppConfiguration()
@ContextConfiguration(classes = {MyController.class, MyExceptionHandler.class})
@EnableWebMvc
public class TeilzahlungControllerTest {
    @Autowired
    private MockMvc mockMvc;
    //test the controller
}

I refactored it from a bulky test, that ran on @SpringBootTest. So now my new test runs about 100 times faster, but it no longer has "all the beans". And it shows on deserialization: certain objects are no longer deserialized correctly, with the biggest example being Instant.

You may also see that I had to "manually" include my "global" Exceptionhandler (MyExceptionHandler.class).

So my question is: how can I make sure that my slim ApplicationContext contains all the beans required, especially those for deserialization? Including them by hand can not be the solution, right?

Many thanks in advance!

Aucun commentaire:

Enregistrer un commentaire