tSQLt - 关于名为 'Setup' 的存储过程 - 在测试之前自动执行

tSQLt - About the Stored proc called 'Setup' - that gets automatically executed prior to test

在 tSQLt 框架中,我们可以在测试 class 下编写名为 'setup' 的存储过程,这确保了无论何时测试或测试套件(class 包含许多测试)运行s,先执行'setup'存储过程,再执行测试。

如果我们 运行 测试 class 只包含一个测试,那么很明显安装 SP 将首先执行,然后再执行测试。但是,假设测试 class 有 5 个测试,我们使用 RunAll 方法执行它们。在这种情况下,设置是否会在每次测试之前执行一次?或者设置 SP 是否只对整个测试套件执行一次。

来自tSQLt doc

tSQLt.Run [ [@testName = ] 'test name' ]

1. Providing a test class name executes all tests in that test class. If a SetUp stored procedure exists in that test class, then it is executed before each test.

RunAll 相同:

tSQLt.RunAll executes all tests in all test classes created with tSQLt.NewTestClass in the current database. If the test class schema contains a stored procedure called SetUp, it is executed before calling each test case