Tutorial: Running tests in ReadyRoll with tSQLt Adapter

Intro

This tutorial helps you get started with running tSQLt tests in ReadyRoll. It uses AdventureWorks.Database as a sample ReadyRoll project, but the steps are applicable to any ReadyRoll project.

As this tutorial requires the use of Programmable Objects, it will not work with ReadyRoll Core edition.

Set up test project

Create a new project

In Visual Studio in your AdventureWorks.Database solution, select New Project from the File menu and create a new ReadyRoll SQL Server Database Project named AdventureWorks.Database.Tests. Do not connect this project to any database at this point.

Switch on Programmable Objects

In the Solution Explorer, right-click the AdventureWorks.Database.Tests project and select Properties. In the Programmable Objects section, select Import into separate script files.

Add a build dependency

Go to the Project menu and select Project Dependencies. Select AdventureWorks.Database to add the dependency to the AdventureWorks.Database.Tests project.

Right-click the AdventureWorks.Database.Tests project in the Solution Explorer. Open Project Dependencies using Build Dependencies > Project Dependencies... and select AdventureWorks.Database to add the dependency.

Set the target database

In the Solution Explorer, right-click the AdventureWorks.Database.Tests project and select Properties. Select Debug tab from the panel on the left and in the Target Connection String section click on the Edit... button. This will open a connection dialog. In this dialog, select the database that the AdventureWorks.Database project is connected to.

The test project has to point at the AdventureWorks.Database target database, as there is no database in AdventureWorks.Database.Test.

Ignore tSQLt in the database project.

Unload the AdventureWorks.Database project by going to the Project menu and click Unload Project. In Solution Explorer, right-click the unloaded project and click Edit AdventureWorks.Database.sqlproj. In AdventureWorks.Database.sqlproj, edit the SyncOptionIgnoretSQLt property to:

<SyncOptionIgnoretSQLt>True</SyncOptionIgnoretSQLt>

Save the file and reload the project using Project > Reload Project.

Write your first tSQLt test

Install the framework

In your AdventureWorks.Database.Tests, in the Migrations folder add a new script and rename it to 0001_Install_tSQLt.sql. Download the Setup script and copy the contents of tSQLt.class.sql into 0001_Install_tSQLt.sql, making sure you leave the Migration ID on the first line.