2017-05-18 3 views
3

일부 tSQLt 테스트를 작성하고 Visual Studio의 테스트 탐색기를 사용하여 tSQLt test adapter 확장을 통해 실행합니다. 나는 TDD을하고 있습니다. 그래서 테스트 할 저장 프로 시저를 작성하기 전에 테스트를 작성하고 있습니다.Visual Studio Test Explorer에서 tSQLt 테스트가 실패 할 때 왜 통과합니까?

테스트를 실행할 때 저장 프로 시저가 아직 존재하지 않으므로 문제가 발생합니다. 여기

test explorer screenshot

: 나는 테스트 탐색기에서 실행하면

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 관리 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 관리 Studio에서 실패하지만 는 테스트 탐색기에서를 전달합니다.

+0

는 Lews 안녕 -이 정확한 일을 시도하고 나를 위해 작동합니다 - 당신은 내게 당신이 사용하는 SQL 서버 및 Visual Studio의 버전을 알 수 있습니까? –

+0

@EdElliott보세요. SQL Server 2008 R2 및 Visual Studio 2015 Enterprise Update 3을 사용하고 있습니다. –

답변

0

테스트 어댑터를 Visual Studio 2017로 업데이트하고 몇 가지 문제점을 수정했습니다. 이 코드는 여기에서 실행되었으므로 재현 할 수 없습니다 (테스트로 인해 Visual Studio에서 오류가 발생 함).

잡아 최신 버전에서 : 그것은 두 가지 버전을 유지하는 의미대로 알려 2015 지원 대 필요한 경우

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

, 나는 주저입니다.

에드

관련 문제