简体   繁体   中英

How to create a stored procedure in TSQLT Set up?

I try to add new TSQLT in .NET solution. Some tests that I implemented use the same code and that's why I would like to create a stored procedure and call it from tests. But for some reasons I see only errors when insert working in SQL management studio code in the test .sql file.

I've tried to put the procedure creation code in the SetUp of TSQLT, but for some reasons, I see that it's not picking up by the runner.

Should my .sql file name be in format classname.SetUp as well or the procedure name should be in such format only?

Thanks!

To actually use the SetUp capability of tSQLt, you only need to add a stored procedure called SetUp within the test class(or schema in SQL Server terms).

For example if you have a test class called testMergingCountryFromStaging then you can create a SetUp stored procedure as below:

CREATE PROCEDURE testMergingCountryFromStaging.SetUp
AS
BEGIN
SET NOCOUNT ON;

-- Now fake the actual tables and
-- only those fields that are actually necessary
-- for stored procedure validation.
EXEC tSQLt.FakeTable @TableName = N'Country', @SchemaName = N'dbo';
EXEC tSQLt.FakeTable @TableName = N'Country', @SchemaName = N'staging';

-- Initialize expected result and actual table
CREATE TABLE expected(CountryName VARCHAR(50) NOT NULL, ActiveForDelivery BIT NOT NULL);
END;
GO

Then, when running the unit tests of the class by executing EXEC tSQLt.Run 'testMergingCountryFromStaging'; , the SetUp stored procedure will be executed by tSQLt first and then will resume with the execution of the actual tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM