3

我正在编写一些 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 中仍然失败,但在测试资源管理器中通过。

4

1 回答 1

1

我已将测试适配器更新为 Visual Studio 2017 并修复了几个问题。我在这里运行了这段代码,但无法重现它(测试导致 Visual Studio 失败)。

从以下位置获取最新版本:

https://marketplace.visualstudio.com/items?itemName=vs-publisher-263684.tSQLtTestAdapterforVisualStudio2017

如果您需要 vs 2015 支持,请告诉我,我很犹豫,因为这意味着要维护两个版本。

于 2017-10-03T13:32:01.390 回答