July 2018
Intermediate to advanced
336 pages
9h 23m
English
Testing is an important part of software engineering and with Spring Boot 2.0 @DataJpaTest is introduced to ease the testing of JPA repositories. This annotation will use an embedded database for testing and will auto-configure TestEntityManager to verify the JPA Repository operations.
The following is the test for CommentRepository:
@RunWith(SpringRunner.class)@DataJpaTestpublic class CommentRepoTest { @Autowired private TestEntityManager testEntityManager; @Autowired private CommentRepository commentRepository; @Test public void findByCreatedYearAndMonthAndDay_HappyPath_ShouldReturn1Comment() { // Given Comment comment = new Comment(); comment.setComment("Test"); comment.setType(CommentType.PLUS);
Read now
Unlock full access