If you write code to SQL Server then you might be interested in this: at the end of 2017 I wrote a tSQLt tdd training course which has helped over 300 people learn both tSQLt and how to apply TDD practices to their SQL Server T-SQL development, you can join the course at https://courses.agilesql.club. The course is free if you are happy to wait 10 weeks to complete it, with 1 lesson being made available per week - if you are in more of a hurry or you would like to help support the project you can purchase the course which makes it instantly available to you.

Running tSQLt tests from C/VB.Net/Java/Whatever

When you already have a test framework setup such as MSTest or NUnit and possibly a CI build in place and you want to add Sql Server tests it is often wise to call the tests from the framework you already have setup.

I do this at the moment using C# and I have a helper method that calls tSQLt.Run/RunClass/RunAll passing in the name of the test(s) to run - this means that from within visual studio, I can see and run all of my tSQLt tests alongside my existing NUnit / Moq tests.

One issue is that the response from tSQLt.Run is human readable, it is basically a string and also comes down the TDS channel for messages rather that responses so with the SqlClient you need to use the “InfoMessage” event and then parse the string - this is one of those things that is a bit of a pain so instead what you can do is to run your unit test using tSQLt.Run and then call “EXEC [tSQLt].[XmlResultFormatter]” this returns the result of the last call to RunAll in a nicely, easily passed string from the normal TDS response so you can use use a standard SqlDataReader to read the first column of the first row.

Update: Everytime I look at tSQLt it gets better and better! There is also a “tSQLt.RunWithXmlResults” which will run a test and return the results as Xml which saves the additional step.

Enjoy!