Do you unit test your database?

Last updated by Anton Polkanov [SSW] about 1 year ago.See history

We've all heard of writing unit tests for code and business logic, but what happens when that logic is inside SQL server?

With Visual Studio, you can write database unit tests. These are useful for testing out:

  • Stored Procedures
  • Triggers
  • User-defined functions
  • Views

These tests can also be added to the same library as your unit, web and load tests.

AddNewTest
Figure: Database Unit Test

WriteUnitTest
Figure: Writing the unit test against a stored proc

If you want to know how to setup database unit tests locally and in your build pipeline, check out this article: Unit Test Stored Procedures and Automate Build, Deploy, Test Azure SQL Database Changes with CI/CD Pipelines

We open source. Powered by GitHub