我正在编写一些 tSQLt 测试并通过tSQLt 测试适配器扩展使用 Visual Studio 的测试资源管理器运行它们。我正在做TDD,所以我在编写它测试的存储过程之前编写测试。
问题是,当我运行测试时,它应该会失败,因为存储过程还不存在。当我在 Sql Server Management Studio 中使用 tSQLt 运行测试时,它会失败:
The module 'test_ValidCustomerName_CustomerIdIs1' depends on the missing object 'dbo.AddCustomer'. The module will still be created; however, it cannot run successfully until the object exists.
(0 row(s) affected)
[AddCustomer].[test_ValidCustomerName_CustomerIdIs1] failed: (Error) Could not find stored procedure 'dbo.AddCustomer'.[16,62]{test_ValidCustomerName_CustomerIdIs1,7}
+----------------------+
|Test Execution Summary|
+----------------------+
|No|Test Case Name |Dur(ms)|Result|
+--+----------------------------------------------------+-------+------+
|1 |[AddCustomer].[test_ValidCustomerName_CustomerIdIs1]| 0|Error |
-----------------------------------------------------------------------------
Msg 50000, Level 16, State 10, Line 1
Test Case Summary: 1 test case(s) executed, 0 succeeded, 0 failed, 1 errored.
-----------------------------------------------------------------------------
但是当我在测试资源管理器中运行它时,它说测试通过了:
这是测试的代码:
EXEC tSQLt.NewTestClass 'AddCustomer';
GO
CREATE PROCEDURE AddCustomer.test_ValidCustomerName_CustomerIdIs1
AS
BEGIN
DECLARE @customerName NVARCHAR(40) = 'John Doe'
EXEC dbo.AddCustomer @customerName
DECLARE @expected INT = 1
, @actual INT = (SELECT CustomerID
FROM dbo.Customer
WHERE Name = @customerName)
EXEC tSQLt.AssertEquals @expected, @actual
END
GO
这是dbo.Customer
表格:
CREATE TABLE dbo.Customer
(
CustomerID INT NOT NULL PRIMARY KEY IDENTITY(1, 1)
, Name NVARCHAR(50) NOT NULL
)
编辑-我已将测试修改为仅调用tSQLt.Fail
:
EXEC tSQLt.NewTestClass 'AddCustomer';
GO
CREATE PROCEDURE AddCustomer.test_ValidCustomerName_CustomerIdIs1
AS
BEGIN
EXEC tSQLt.Fail 'Test should fail'
END
GO
测试在 Sql Server Management Studio 中仍然失败,但在测试资源管理器中通过。