liveBook · Manning

Database sharing

As explained in Unit Testing Principles, Practices, and Patterns

A shared database is a database whose data is accessed by more than one application or system.

Database sharing occurs when multiple applications access the same database. It couples systems and complicates independent development, so APIs or message buses are preferable whenever feasible. section 8.2

When a shared database is unavoidable:

  • Treat tables visible to other applications as an unmanaged dependency; their rows effectively act as messages. section 8.2
  • Mock interactions with shared tables to preserve the existing communication pattern, and avoid changing them unless absolutely necessary. section 8.2
  • Treat application-only tables as a managed dependency and verify the database’s final state rather than interactions. section 8.2
Figure 8.5. Treat the part of the database that is visible to external applications as an unmanaged dependency. Replace it with mocks in integration tests. Treat the rest of the database as a managed dependency. Verify its final state, not interactions with it.

Use the database boundary diagram to distinguish externally visible tables from application-owned tables and select the corresponding integration-test strategy. section 8.2

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Classifies database parts by ownership and prescribes mocks or final-state verification, while stopping short of migration guidance.
Examples
Uses externally visible tables, application-only tables, rows as messages, mocks, and final database state as examples.
What it assumes
Assumes integration-testing concepts and distinguishes externally visible data from application-managed data.
What you can do after
Configure integration tests by mocking shared-table communication and verifying final state for application-owned data.
How it connects
Connects shared databases with integration testing, APIs, message buses, mocks, and managed or unmanaged dependencies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.