Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Drawio
borderfalse
diagramNameCPS DB Testing Unit vs Integration
simpleViewerfalse
width
linksauto
tbstyleinline
lboxfalse
diagramDisplayName
diagramWidth851
revision67

While using unit tests is a common approach for Java application testing, it seems insufficient  in a context of testing the
actual data persistence/retrieval functionality:

  • Test covers a small slice of functionality while the major piece served by external services (Spring data framework,
    JDBC driver and database itself) remain not used (not tested)
  • JPA repositories can be only used as mocks to test the service implementation; the implementation but JPA repositories are not subject
    for tests themselves because of definition as interfaces
  • The effort to setup the expected behaviors
    for expected behaviors for JPA repository mocks is comparable with (or exceeds) the effort
    required to setup the actual data for same cases;
    but JPA repositories are not subject for unit tests

From other hand the benefits of using integration tests with real database instance are following:

  • All levels of abstraction are involved in tests, it means all of them are impacting on test results same way as within
    a deployed application
  • JPA repositories are subjects of test
  • Complete validation of expected behavior, including database schema initialization
  • Can be used on build, keeping desired level of reliability and consistency
  • Tests can be used on development stage making the database deployment (on dev environment) optional

Components

Drawio
borderfalse
diagramNameCPS DB Testing components diagram
simpleViewerfalse
width
linksauto
tbstyleinline
lboxfalse
diagramDisplayName
diagramWidth721
revision1



Test Containers

Test container life circle management

...