Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
Databases, SQL & BIDatabase conceptSeniorCommonTest design

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

Test a view at its public result boundary
Dialect · Portable SQLRuntime · SQLite sample DB

Runs against the resettable SQLite sample database used by the playground.

SQL
SQLite · sample DB · browser sandbox
Result
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.

#database#sql#stored-procedures#triggers

Sources

PostgreSQL documentationPostgreSQL Global Development Group · Relational modelling, SQL, joins, constraints, transactions, concurrency, indexes, query plans and recovery