My goal was to create something that was easy to use, easy to debug and easy to get started. SqlTest is meant to be used in a C# test project in conjunction with a test harness like nunit or mstest. I’m well aware that most SQL / SSIS developers do not live in .net and some are downright afraid of it. In fact, another popular testing framework, tSQLt , is an excellent option for many projects because you can write tests in native SQL, plus you get all the goodies that come with it, such as fakes. However, there were several reasons why I chose to go my own way:
The initial release of SqlTest contains the essentials for testing. Methods for:
There are certainly some other features which will be useful, like executing a package from the file system for those poor souls who’ve yet to migrate to the project model. And there are some things which are less useful, like asserts on a dataset, which tends to be very fragile. I will plan to add more in time – as well, I hope for some suggested features from you.
There’s documentation about how it works here: https://github.com/MarkWojciechowicz/SqlTest/wiki
I encourage you to try it out today, this is an excellent compliment for any SSDT database project. Just create a new c# project in the same solution.You can install SqlTest from nuget by opening the Package Manager Console in visual studio and typing Install-Package SqlTest.
A sample comes with the install, but below is a quick example to see how to use it.
Enjoy!
using System ; using NUnit.Framework ; using SqlTest ; using System.Transactions ; namespace mynamespace.Tests { public class UnitUnderTest { TransactionScope scope; SqlTest.SqlTestTarget dataWarehouseDb; [SetUp] public void Setup () { scope = new TransactionScope(); dataWarehouseDb = new SqlTest.SqlTestTarget( "DataWarehouse" ); } [TearDown] public void Teardown () { if (Transaction.Current.TransactionInformation.Status == TransactionStatus.Active) { scope.Dispose(); } } [Test] public void UnitUnderTest_Action_ExpectedOutcome () { //Arrange dataWarehouseDb.ExecuteAdhoc( $ "Truncate table / Insert test data;" ); //Act dataWarehouseDb.ExecuteAdhoc( $ "Exec proc;" ); //Assert var actual = dataWarehouseDb.GetActual( "Select scalar value to test outcome" ); Assert.That(actual, Is.EqualTo( "Expected Value" )); //The teardown method runs after every test and will rollback all actions in one transaction } [TestCase("SomeValue", 1)] [TestCase("SomeOtherValue", 2)] public void UnitUnderTest_Action_ExpectedOutcome ( string param, object expected) { //Arrange dataWarehouseDb.ExecuteAdhoc( $ "Truncate table / Insert test data;" ); //Act dataWarehouseDb.ExecuteAdhoc( $ "Exec proc @param = {param};" ); //Assert var actual = dataWarehouseDb.GetActual( "Select to check result" ); Assert.That(actual, Is.EqualTo(expected)); } } }