Don’t try to unit test controller request validation, because MockMvc is a container-less spring platform that means exception resolver will not be activated during controller unit test. MethodArgumentNotValidException will not be resolved and you will get an empty response body with desired status(400 Bad Request) on your response inside unit test section. The best way to test controller request validation for bad request assertion is testing it inside integration tests of controllers.
Don’t Try to Unit Test Controller Request Validation
Huseyin BABAL Uncategorized 1 Minute
Published by Huseyin BABAL
Building Hazelcast Cloud to provide Hazelcast Cluster as a service with extensive features. AWS Certified DevOps Professional. Building highly scalable, real-time systems with Spring Boot, Kubernetes, Docker, Prometheus, Event-Based Systems, and Hybrid Cloud. Ex. Sony and eBay engineer View all posts by Huseyin BABAL