我是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;
Run Code Online (Sandbox Code Playgroud)
通常,您要测试的存储过程依赖于其他表或其他存储过程。因此,您还应该熟悉FakeTable和SpyProcedure:http ://tsqlt.org/user-guide/isolating-dependencies/
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |