Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 为什么在VisualStudioTestExplorer中tSQLt测试应该失败时却通过了?_Sql Server_Unit Testing_Visual Studio 2015_Sql Server Data Tools_Tsqlt - Fatal编程技术网

Sql server 为什么在VisualStudioTestExplorer中tSQLt测试应该失败时却通过了?

Sql server 为什么在VisualStudioTestExplorer中tSQLt测试应该失败时却通过了?,sql-server,unit-testing,visual-studio-2015,sql-server-data-tools,tsqlt,Sql Server,Unit Testing,Visual Studio 2015,Sql Server Data Tools,Tsqlt,我正在编写一些tSQLt测试,并通过扩展使用VisualStudio的测试资源管理器运行它们。我正在这样做,所以我在编写它测试的存储过程之前先编写测试 问题是,当我运行测试时,它应该失败,因为存储过程还不存在。当我在Sql Server Management Studio中使用tSQLt运行测试时,它会像应该的那样失败: The module 'test_ValidCustomerName_CustomerIdIs1' depends on the missing object 'dbo.Add

我正在编写一些tSQLt测试,并通过扩展使用VisualStudio的测试资源管理器运行它们。我正在这样做,所以我在编写它测试的存储过程之前先编写测试

问题是,当我运行测试时,它应该失败,因为存储过程还不存在。当我在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中的测试仍然失败,但它通过了测试资源管理器中的测试。

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

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

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


ed

嘿,Lews-我已经尝试过这个东西,它对我很有效-你能告诉我你正在使用的SQL Server和Visual Studio的版本吗?@EdElliott谢谢你的关注。我正在使用SQL Server 2008 R2和Visual Studio 2015企业更新3。