If you write code to SQL Server then you might be interested in this: I have written a tSQLt tdd training course which has helped over 500 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.

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!

Subscribe

* indicates required

Please select all the ways you would like to hear from Agile Sql Club:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.