Skill 2.3.1
Design and implement a testing strategy, including unit tests and integration tests
Key Concepts
Unit tests check one object in isolation, such as a function's result for given inputs or a procedure's effect on faked tables. The tSQLt framework provides test classes, tSQLt.FakeTable, tSQLt.SpyProcedure and assertions such as tSQLt.AssertEqualsTable, and each test runs in a transaction that is rolled back. tSQLt relies on SQL CLR, so it runs on SQL Server (including containers) rather than Azure SQL Database. The build itself is also a test: building a SQL project validates syntax and references, and code analysis rules flag problems such as SELECT *.
Integration tests deploy the built dacpac to a real database, often an ephemeral SQL Server container or a short-lived Azure SQL database created by the pipeline, then load test data and check behaviour across objects and with the application, such as an API call returning the expected JSON. Pull request pipelines run the build, unit tests and integration tests as required status checks, and a deployment to a staging database with a deploy report precedes production.