2017-05-18 32 views
3

我正在寫一些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. 
----------------------------------------------------------------------------- 

但是,當我在測試資源管理器中運行它,它說,測試通過:

test explorer screenshot

這裏當我運行在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傳遞

+0

嘿L CWS個 - 我已經嘗試了這個確切的事情,它爲我的作品 - 你能告訴我你是使用SQL Server和Visual Studio的版本? –

+0

@EdElliott感謝您的關注。我正在使用SQL Server 2008 R2和Visual Studio 2015 Enterprise Update 3。 –

回答

相關問題