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.

Why is my tSQLt test not running?

I wrote a test earlier and forgot one of the two cardinal rules about tSQLt so I was running my test suite and the test did not run, I re-deployed and it still didn’t run so I thought I would create this handy list of things to check that mean that even when the tests exist in the database they do not run:

  • Are the tests in a schema that has the tSQLt test class extended property?
  • Does the name of the test start with the word “test”? If it doesn’t then it will not actually run

Test schema extended property

You need to create a schema which is basically the test class:

CREATE SCHEMA [thingy_a_bob]
EXECUTE sp_addextendedproperty
@name = N’tSQLt.TestClass’
, @value = 1
, @level0type = N’SCHEMA’
, @level0name = N’thingy_a_bob’;

If the lovel0name does not match the name of the schema then it won’t actually apply to it so make sure that it is correct.

test name

The test MUST begin with the word test so this is valid:

create procedure [thingy_a_bob].[test this does something cool] as ...

but this is invalid:

create procedure [thingy_a_bob].[this does something cool] as ...

If this doesn’t help?

If you have checked both of these things then go back to making sure that the test is actually deployed!