【问题标题】:Why does a tSQLt test pass in Visual Studio Test Explorer when it should fail?为什么在 Visual Studio 测试资源管理器中应该失败的 tSQLt 测试通过?
【发布时间】:2017-05-18 16:36:33
【问题描述】:

我正在编写一些 tSQLt 测试并通过 tSQLt test adapter 扩展使用 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 中仍然失败,但在测试资源管理器中通过

【问题讨论】:

  • 嘿 Lews - 我已经尝试过这个确切的东西,它对我有用 - 你能告诉我你正在使用的 SQL Server 和 Visual Studio 的版本吗?
  • @EdElliott 感谢您的浏览。我正在使用 SQL Server 2008 R2 和 Visual Studio 2015 Enterprise Update 3。

标签: sql-server unit-testing visual-studio-2015 sql-server-data-tools tsqlt


【解决方案1】:

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

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

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

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

编辑

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多