我正在写一些tSQLt测试,并使用Visual Studio的测试浏览器通过tSQLt test adapter扩展来运行它们。我在做TDD,所以我在编写测试的存储过程之前编写测试。为什么tSQLt测试在失败时会通过Visual Studio Test Explorer?
问题是,当我运行测试时,它应该失败,因为存储过程尚不存在。
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.
-----------------------------------------------------------------------------
但是,当我在测试资源管理器中运行它,它说,测试通过:
这里当我运行在SQL Server Management Studio中tSQLt测试它像它应该失败对于测试的代码:
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,但它在测试IE传递。
嘿L CWS个 - 我已经尝试了这个确切的事情,它为我的作品 - 你能告诉我你是使用SQL Server和Visual Studio的版本? –
@EdElliott感谢您的关注。我正在使用SQL Server 2008 R2和Visual Studio 2015 Enterprise Update 3。 –