gpt4 book ai didi

tSQLt - 测试列是否由存储过程输出

转载 作者:行者123 更新时间:2023-12-02 01:02:50 28 4
gpt4 key购买 nike

我是 tSQLt 的新手,在进行真正应该非常简单的测试时遇到了一些困难。

我在存储过程中执行的 SELECT 语句中添加了一列。

如何在 tSQLt 测试中测试该列是否包含在该存储过程的结果集中?

最佳答案

通常,在将列添加到存储过程的输出时,您需要测试该列是否存在并且是否填充了正确的数据。由于我们要确保列中填充的是相同的数据,因此我们可以设计一个测试来实现这一点:

CREATE PROCEDURE MyTests.[test stored procedure values MyNewColumn correctly]
AS
BEGIN
-- Create Actual and Expected table to hold the actual results of MyProcedure
-- and the results that I expect
CREATE TABLE MyTests.Actual (FirstColumn INT, MyNewColumn INT);
CREATE TABLE MyTests.Expected (FirstColumn INT, MyNewColumn INT);

-- Capture the results of MyProcedure into the Actual table
INSERT INTO MyTests.Actual
EXEC MySchema.MyProcedure;

-- Create the expected output
INSERT INTO MyTests.Expected (FirstColumn, MyNewColumn)
VALUES (7, 12);
INSERT INTO MyTests.Expected (FirstColumn, MyNewColumn)
VALUES (25, 99);


-- Check that Expected and Actual tables contain the same results
EXEC tSQLt.AssertEqualsTable 'MyTests.Expected', 'MyTests.Actual';
END;

通常,您正在测试的存储过程依赖于其他表或其他存储过程。因此,您还应该熟悉 FakeTable 和 SpyProcedure:http://tsqlt.org/user-guide/isolating-dependencies/

关于tSQLt - 测试列是否由存储过程输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26406487/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com