Michael
Michael

Reputation: 597

tSQLt not running tests

I have an installation that used to work, but now appears not to. Wondering if anyone else has experienced this.

Tests that once ran now dont. Nothing appears to run. The output is always as follows:

+----------------------+ |Test Execution Summary| +----------------------+

|No|Test Case Name|Result|

+--+--------------+------+

Test Case Summary: 0 test case(s) executed, 0 succeeded, 0 failed, 0 errored.

Upvotes: 4

Views: 2592

Answers (4)

rafiquenazir
rafiquenazir

Reputation: 306

In my case :

1. WITH ERROR,0 TEST CASE EXECUTED

EXEC tSQLt.NewTestClass @ClassName = N'BasicTests'  ;
GO
CREATE PROCEDURE [BasicTests].[ test assertEquals]  AS
BEGIN

DECLARE  @expected INT;
 SET @expected=1;
 DECLARE @actual INT ;
 SET @actual=1;
    EXEC tSQLt.AssertEquals @expected, @actual;

END;


GO



EXEC tSQLt.RunALL -- OR EXEC tSQLt.Run '[BasicTests]';  --

=====================

OUTPUT

(0 row(s) affected)

+----------------------+ |Test Execution Summary| +----------------------+

|No|Test Case Name|Dur(ms)|Result|

+--+--------------+-------+------+

Test Case Summary: 0 test case(s) executed, 0 succeeded, 0 failed, 0 errored.

2. WITHOUT ERROR, TEST CASE EXECUTED-PROBLEM SEEMS IN NAMING TEST PROCEDURE

EXEC tSQLt.NewTestClass 'testBasic';
GO

CREATE PROCEDURE testBasic.[test assertEquals]
AS
BEGIN
DECLARE  @expected INT;
 SET @expected=1;
 DECLARE @actual INT ;
 SET @actual=1;
    EXEC tSQLt.AssertEquals @expected, @actual;

END;
GO

EXEC tSQLt.RunALL  --OR EXEC tSQLt.Run '[testBasic]'; --

==========================

OUTPUT

(0 row(s) affected)

+----------------------+ |Test Execution Summary| +----------------------+

|No|Test Case Name |Dur(ms)|Result | +--+-------------------------------+-------+-------+

|1 |[testBasic].[test assertEquals]| 0|Success|

Test Case Summary: 1 test case(s) executed, 1 succeeded, 0 failed, 0 errored.

Finallly,Test Classes can be viewed or dropped as follows:

SELECT Name, SchemaId FROM tSQLt.TestClasses;

EXEC tSQLt.DropClass 'testBasic'

Upvotes: 0

Diorcula
Diorcula

Reputation: 115

Well after a night of struggle i found something that worked for me:

I deleted all my stored procedures i created for the tests. (note that they can be found in the database map under External Resources -> Programmability -> Stored Procedures and then they are probably on the top of the list.)

then i made sure to run the newTestClass again (only these lines):

EXEC tSQLt.NewTestClass 'testJobs';
GO

Then i ran all my stored procedures/ test one by one again, for example this one:

CREATE PROCEDURE testJobs.[testing simple UTC]

AS
BEGIN

    DECLARE @sum INT;
    SELECT @sum = 3 + 2;

    EXEC tSQLt.AssertEquals 5, @sum;

END;
GO

The code should start with ""create procedure" and end with the "end; go" lines. Ran these one by one and could then execute the total testclass with:

EXEC tSQLt.Run 'testJobs';

Hope this helps.

Darcula

Upvotes: 0

Andrew
Andrew

Reputation: 5277

Your question doesn't give a huge amount of detail. What produced the output above? EXEC tSQLt.RunAll or maybe EXEC tSQLt.Run 'MyTests'. One thing to be aware of is that if you have a test class that is already in existence (say 'MyTests') and you run EXEC tSQLt.NewTestClass 'MyTests' again it will clear all existing tests from the test class.

Try this out.

EXEC tSQLt.NewTestClass 'MyTests'
GO

CREATE PROCEDURE MyTests.testThisOut
AS
BEGIN
    EXEC tSQLt.Fail 'this should not work'
END
GO

EXEC tSQLt.NewTestClass 'MyTests'
GO

EXEC tSQLt.Run 'MyTests'
GO

Upvotes: 1

Michael
Michael

Reputation: 597

The test procs must begin with the all lowercase keyword test. [test to start the name is fine. All other sprocs are ignored. This was demonstrated in the code, but someone (ahem) decided to number the tests to make an order. The numbers need to go after the test keyword. Now I have tests that pass/fail again!

Upvotes: 19

Related Questions