What should be tested when business logic is implemented in views, stored procedures or triggers?
Answer
Verify the declared inputs, result shape, permissions, transaction boundaries, side effects and error behaviour of stored procedures, plus row visibility and freshness for normal or materialized views. Triggers need tests for every firing operation, ordering, recursion, bulk statements, rollback, disabled states and unexpected writes to audit or derived tables. Cover direct and application-mediated access, schema changes, performance at realistic volume and observability so hidden database logic does not become an untraceable second application.
Strong answer includes
- covers permissions, transactions and hidden side effects
- tests trigger firing, recursion and bulk behaviour
- includes schema compatibility, performance and observability
Practical example
Runs against the resettable SQLite sample database used by the playground.
Run the query to see the result.
A view should be tested for result shape, filtering, permissions, freshness and performance just like another public query contract. Procedures and triggers add inputs, transaction boundaries and hidden side effects that require additional direct and application-mediated tests.
Expected result: The view exposes the same paid-order total that an independently calculated source query produces.