Why does the tSQLt test pass in Visual Studio Explorer if it doesn't work?

I am writing some tSQLt tests and running them with Visual Studio Test Explorer using the tSQLt test adapter extension . I am doing TDD , so I am writing a test before writing the stored procedure that it tests.

The problem is that when I run the test, it should fail because the stored procedure doesn't exist yet. When I run a test with tSQLt in Sql Server Management Studio it doesn't work like this:

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.
-----------------------------------------------------------------------------

      

But when I run it in Test Explorer, it says that the test passes:

screenshot of test conductor

Here's the code for the test:

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

      

And here is the table dbo.Customer

:

CREATE TABLE dbo.Customer
(
    CustomerID  INT             NOT NULL    PRIMARY KEY IDENTITY(1, 1)
  , Name        NVARCHAR(50)    NOT NULL
)

      

EDIT . I modified the test to just call tSQLt.Fail

:

EXEC tSQLt.NewTestClass 'AddCustomer';
GO

CREATE PROCEDURE AddCustomer.test_ValidCustomerName_CustomerIdIs1
AS
BEGIN   
    EXEC tSQLt.Fail 'Test should fail'
END
GO

      

The test still fails in Sql Server Management Studio, but submits to Test Explorer.

+3


source to share


1 answer


I updated my test adapter for visual studio 2017 and fixed a couple of issues. I ran this code here and cannot reproduce it (tests crash in visual studio).

Grab the latest version:

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



If you need support for vs 2015 please let me know, I hesitate as it means keeping two versions.

e ed

0


source







All Articles