How to test if @Valid annotation is working?
问题 I have the following unit test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {EqualblogApplication.class}) @WebAppConfiguration @TestPropertySource("classpath:application-test.properties") public class PostServiceTest { // ... @Test(expected = ConstraintViolationException.class) public void testInvalidTitle() { postService.save(new Post()); // no title } } The code for save in PostService is: public Post save(@Valid Post post) { return postRepository.save