DBConfirm - Official Documentation
Introduction
A C#-based testing framework to write and run tests for logic within SQL Server
What is DBConfirm?
DBConfirm is a unit testing framework for SQL Server databases from within .Net projects. Tests can be written to check that stored procedures and views behave as you'd expect, and can be used to help reduce the number of bugs introduced. DBConfirm also provides patterns and tools to easily set up prerequisite data needed for your tests.
Why?
Developers are pretty good at writing unit tests for their application logic already, but sometimes database logic (stored procedures, views, etc.) can be overlooked. A big reason is that traditionally SQL unit tests are difficult to write, or have a very steep learning curve. DBConfirm aims to solve this by allowing SQL tests to be written in the same way that all other unit tests are written, so that they are easy to write, easy to maintain, and easy to run.
How?
The DBConfirm framework is designed to execute tests against a physical instance of the database under test, and ensures that each test run is accurate and repeatable by making sure all effects of a test are rolled back when the test has finished.
DBConfirm also provides a number of ways to easily assert the results of your tests.
Is it free?
Yes.
You can even check out the source code over at github.com/Bungalow64/DBConfirm.
What does a DBConfirm test look like?
A simple test (in MSTest) to call a stored procedure then verify that the data has been added, looks like this:
[TestMethod]
public async Task AddUserProcedure_UserIsAdded()
{
// Call a stored procedure with some parameters
await TestRunner.ExecuteStoredProcedureNonQueryAsync("dbo.AddUser", new DataSetRow
{
["FirstName"] = "Jamie",
["LastName"] = "Burns",
["EmailAddress"] = "jamie@example.com"
});
// Get all the data in a table
QueryResult data = await TestRunner.ExecuteTableAsync("dbo.Users");
// Make some assertions on the data
data
.AssertRowCount(1) // Asserts that there is only 1 row
.AssertValue(0, "FirstName", "Jamie"); // Asserts that "FirstName" is "Jamie" in the first row
}
What versions of SQL Server does DBConfirm work with?
DBConfirm is compatible with SQL Server 2014, 2016, 2017, 2019, 2022 and with Azure SQL Database.
Getting started
See the Quick Start guide for getting started.