0

我正在尝试做一些 Tsqlt 测试,我想将我的数据与测试分开。

所以我有一个带有数据的程序:

alter PROCEDURE [Test_Calss].[test Data_Test]
AS
BEGIN
EXEC tSQLt.FakeTable 'Sales.Customers';

INSERT INTO Sales.Customers(custid, companyname, contactname, contacttitle,    address, city, region, postalcode, country, phone, fax)
VALUES(1, N'Customer NRZBB', N'Allen, Michael', N'Sales Representative', N'teste Str. 0123', test', NULL, N'122', test', N'01-342789',  N'030-033456');

我还有另一个程序,我想在其中使用假表:

ALTER PROCEDURE [Test_Calss].[test Count_Customer]
AS
BEGIN

EXEC tSQLt.FakeTable 'Sales.Customers';

DECLARE @testres INT; SET @testres = 91;

DECLARE @counter INT;
SELECT @counter = COUNT(*) FROM [Test_Calss].[test Data_Test];

      EXEC tSQLt.AssertEquals @testres,@counter;

END;

我需要第一个过程 [Test_Calss].[test Data_Test] 中的假表在第二个过程中被调用和测试。我尝试使用 EXEC,但它没有用。

任何想法如何调用表格及其内容?

4

1 回答 1

1

我这样做的方法是SetUp在我的TestClass. 我非常自由地使用测试类(就像我在 C# 中所做的那样),因此如果我真的需要,每个存储过程可能有多个测试类。

所以在你的情况下,我会:

create PROCEDURE [Test_Calss].[SetUp]
AS
BEGIN
EXEC tSQLt.FakeTable 'Sales.Customers';

INSERT INTO Sales.Customers(custid, companyname, contactname, contacttitle,    address, city, region, postalcode, country, phone, fax)
VALUES(1, N'Customer NRZBB', N'Allen, Michael', N'Sales Representative', N'teste Str. 0123', test', NULL, N'122', test', N'01-342789',  N'030-033456')
go


create PROCEDURE [Test_Calss].[test Count_Customer]
AS
BEGIN

DECLARE @testres INT; SET @testres = 91;

DECLARE @counter INT;
SELECT @counter = COUNT(*) FROM Sales.Customer;

EXEC tSQLt.AssertEquals @testres,@counter;

END;
go

exec tSQLt.RunTestClass 'Test_Calss';

tSQTtSetUp在每次测试之前调用存储过程,TestClass因此您可以使用它来准备您的常用数据。

于 2017-02-15T09:45:17.423 回答