20 Testing Java persistence applications

This chapter covers

  • Introducing the testing pyramid and examining persistence testing in its context
  • Creating a persistence application to test using Spring Boot
  • Using the Spring TestContext Framework
  • Working with Spring profiles to test Java persistence applications
  • Using execution listeners to test Java persistence applications

All code needs to be tested. During development, we code, compile, and run. When we run, we may sometimes test how our code works. Testing persistence applications involves more than this. In those cases, our code interacts with the external database, and how our program works may be dependent on it.

20.1 Introducing the test pyramid

In previous chapters, we focused on developing code that interacts with a database. We examined different alternatives for doing this, and different frameworks, and we interacted with various databases. Now we need to make sure that our programs are safe and bug-free. We need to be able to introduce changes without creating bugs, add new features without affecting the old features, and refactor code without breaking existing functionality. That is the purpose of this final chapter.

20.2 Creating the persistence application to test

20.3 Using the Spring TestContext Framework

20.4 The @DirtiesContext annotation

20.5 @Transactional execution

20.6 The @BeforeTransaction and @AfterTransaction annotations

20.7 Working with Spring profiles

20.8 Working with test execution listeners

Summary

sitemap