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]
go
EXECUTE sp_addextendedproperty
@name = N’tSQLt.TestClass’
, @value = 1
, @level0type = N’SCHEMA’
, @level0name = N’thingy_a_bob’;
go

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!