Why does a tSQLt test pass in Visual Studio Test Explorer when it should fail?

Viewed 558

I'm writing some tSQLt tests and running them using Visual Studio's Test Explorer via the tSQLt test adapter extension. I'm doing TDD, so I'm writing the test before writing the stored procedure that it tests.

The problem is, when I run the test, it should fail because the stored procedure does not exist yet. When I run the test with tSQLt in Sql Server Management Studio it fails like it should:

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 the test passes:

test explorer screenshot

Here is 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 dbo.Customer table:

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

EDIT - I've 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 it passes in Test Explorer.

1 Answers
Related