Integration Testing in Pipelines
This lesson explains ephemeral test databases, what integration tests check and how they gate pull requests.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish between container and short-lived Azure SQL test databases.
- Identify what integration tests should verify.
- Explain how required status checks enforce testing.
Ephemeral databases
Integration tests need a real database that each pipeline run creates fresh, so runs do not interfere with each other. Two common options are a SQL Server container started as a service in the pipeline job, which is free and fast, and a short-lived Azure SQL database created from a template and deleted after the run, which tests platform-specific behaviour such as Microsoft Entra authentication or features only in Azure SQL Database. The dacpac built earlier in the pipeline is published to that database, followed by seed data.
jobs:
integration:
runs-on: ubuntu-latest
services:
sql:
image: mcr.microsoft.com/mssql/server:2025-latest
env: { ACCEPT_EULA: "Y", MSSQL_SA_PASSWORD: "${{ secrets.TEST_SA_PASSWORD }}" }
ports: ["1433:1433"]
steps:
- uses: actions/checkout@v4
- run: dotnet build database/Inventory.sqlproj -c Release
- run: dotnet tool install -g microsoft.sqlpackage
- run: >
sqlpackage /Action:Publish /SourceFile:database/bin/Release/Inventory.dacpac
/TargetConnectionString:"Server=localhost;Database=Inventory;User ID=sa;Password=${{ secrets.TEST_SA_PASSWORD }};TrustServerCertificate=True"
- run: dotnet test tests/Inventory.IntegrationTestsA database for each run
What integration tests check
Integration tests exercise behaviour across objects and layers, as the following list describes.
- The dacpac deploys cleanly to an empty database and to a database at the previous release's schema (upgrade path).
- Procedures, views and triggers work together on realistic data, including concurrency-sensitive paths.
- The application or Data API builder returns the expected JSON from the deployed schema.
- Security rules hold end to end, such as RLS filtering through the API.
- Performance-sensitive queries stay within agreed limits on representative data volumes.
What integration tests cover
Test data and pipeline gates
Test data is synthetic or masked, never copied production personal data, and is loaded by scripts kept in the repository so each run starts from a known state. The workflow that runs unit and integration tests is configured as a required status check in the main branch's protection rules, so a pull request cannot merge until tests pass. Test results and deploy reports are published as pipeline artifacts for reviewers.
Test data and gates
Proving an upgrade works
A release adds a NOT NULL column to a large table and a procedure that uses it. Unit tests pass, but the team worries that the deployment fails on databases that already contain data. How should the pipeline test this?
Add an integration test job that restores or builds a database at the previous release's schema with representative seed data in a container, publishes the new dacpac to it and runs the tests. This exercises the real upgrade path, where a NOT NULL column without a default fails on existing rows (or needs GenerateSmartDefaults). Deploying only to an empty database would not reveal the problem.
Why test deployment to a database at the previous release's schema, not only an empty one?
Show answer
Upgrades alter existing tables with data, which can fail where a clean deployment succeeds, for example adding a NOT NULL column without a default.
Exam Tips
Remember for the exam
- Fresh database per run: a SQL Server service container or a short-lived Azure SQL database.
- Test both clean deployments and upgrades from the previous schema.
- Use synthetic or masked test data, never production personal data.
- Make the test workflow a required status check on main.