-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathsnippets.sql
More file actions
172 lines (152 loc) · 8.65 KB
/
snippets.sql
File metadata and controls
172 lines (152 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--tab
--tSQLt: about [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
/*
-----------------
-- About tSQLt --
-----------------
tSQLt is an open source unit testing framework for SQL Server.
tSQLt is coauthored by:
- Dennis Lloyd Jr. ( @dennislloydjr | http://curiouslycorrect.com/ )
- Sebastian Meine ( @sqlity | http://sqlity.net )
You can download tSQLt at http://tSQLt.org/downloads
A more complete set of SQL Prompt snippets is available there too.
tSQLt provides an array of procedures that help you to write robust test cases
by isolating dependencies (e.g. tSQLt.FakeTable or tSQLt.SpyProcedure) and
asserting correct behavior (e.g. tSQLt.AssertEqualsTable or tSQLt.ExpectException).
To create a test, you first need to create a schema using the tSQLt.NewTextClass
procedure. Any procedure that lives in such a schema and that has a name that
begins with the four letters "test" is considdered a test case. To execute a test
just run tSQLt.Run passing in either the schema name or the fully qualified
test case name. To execute all test cases in the database run tSQLt.RunAll
You can find the tSQLt manual and examples at http://tsqlt.org/user-guide/
To check the version of tSQLt that is currently installed execute this query:
SELECT * FROM tSQLt.Info();
The Version and the ClrVersion should always match.
For an easier way to manage and execute your tests check out Red Gate SQL Test.
Below is a test case template that also explains the three parts that every
test should contain.
*/
GO
-- Comments here are associated with the test.
-- For test case examples, see: http://tsqlt.org/user-guide/tsqlt-tutorial/
CREATE PROCEDURE [<Test_Class,sysname,>].[<Test_Name,sysname,test >]
AS
BEGIN
--Assemble
-- This section is for code that sets up the environment. It often
-- contains calls to methods such as tSQLt.FakeTable and tSQLt.SpyProcedure
-- along with INSERTs of relevant data.
-- For more information, see http://tsqlt.org/user-guide/isolating-dependencies/
--Act
-- Execute the code under test like a stored procedure, function or view
-- and capture the results in variables or tables.
--Assert
-- Compare the expected and actual values, or call tSQLt.Fail in an IF statement.
-- Typical Asserts: tSQLt.AssertEquals, tSQLt.AssertEqualsString, tSQLt.AssertEqualsTable
-- For a complete list, see: http://tsqlt.org/user-guide/assertions/
EXEC tSQLt.Fail 'TODO:Implement this test.'
END;
GO
---------------------------------------------------------------------------------------------------------
--tac
--tSQLt.ApplyConstraint [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.ApplyConstraint @TableName = '$CURSOR$', @ConstraintName = '';
---------------------------------------------------------------------------------------------------------
--tmt
--tSQLt.AssertEmptyTable [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertEmptyTable @TableName = '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--te
--tSQLt.AssertEquals [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertEquals @Expected = '$CURSOR$', @Actual;
---------------------------------------------------------------------------------------------------------
--tes
--tSQLt.AssertEqualsString [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertEqualsString @Expected = '$CURSOR$', @Actual;
---------------------------------------------------------------------------------------------------------
--tet
--tSQLt.AssertEqualsTable [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertEqualsTable '#Expected','#Actual';
---------------------------------------------------------------------------------------------------------
--tal
--tSQLt.AssertLike [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertLike @ExpectedPattern = '$CURSOR$', @Actual;
---------------------------------------------------------------------------------------------------------
--tne
--tSQLt.AssertNotEquals [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertNotEquals @Expected = '$CURSOR$', @Actual;
---------------------------------------------------------------------------------------------------------
--toe
--tSQLt.AssertObjectExists [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.AssertObjectExists @ObjectName = '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--tco
--tSQLt.CaptureOutput [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.CaptureOutput '$CURSOR$';
SELECT *
INTO #Actual
FROM tSQLt.CaptureOutputLog;
---------------------------------------------------------------------------------------------------------
--txe
--tSQLt.ExpectException [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.ExpectException @ExpectedMessage = '$CURSOR$', @ExpectedSeverity = NULL, @ExpectedState = NULL;
---------------------------------------------------------------------------------------------------------
--txp
--tSQLt.ExpectException:Pattern [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.ExpectException @ExpectedMessagePattern = '$CURSOR$', @ExpectedSeverity = NULL, @ExpectedState = NULL;
---------------------------------------------------------------------------------------------------------
--tf
--tSQLt.Fail [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.Fail '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--tft
--tSQLt.FakeTable [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.FakeTable @TableName = '$CURSOR$', @Identity = 0, @ComputedColumns = 0, @Defaults = 0;
---------------------------------------------------------------------------------------------------------
--tnc
--tSQLt.NewConnection [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.NewConnection @command='$CURSOR$';
---------------------------------------------------------------------------------------------------------
--tnt
--tSQLt.NewTestClass [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.NewTestClass '$CURSOR$';
GO
CREATE PROCEDURE .[test ]
AS
BEGIN
END;
GO
---------------------------------------------------------------------------------------------------------
--tro
--tSQLt.RemoveObject [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.RemoveObject @ObjectName = '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--trf
--tSQLt.ResultSetFilter [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.ResultSetFilter @ResultsetNo = 1, @Command = '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--tsp
--tSQLt.SpyProcedure [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.SpyProcedure @ProcedureName = '$CURSOR$', @CommandToExecute = NULL;
---------------------------------------------------------------------------------------------------------
--tso
--tSQLt.SuppressOutput [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
EXEC tSQLt.SuppressOutput @command = '$CURSOR$';
---------------------------------------------------------------------------------------------------------
--tea
--tSQLt: create #Expected from #Actual [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
SELECT TOP(0) *
INTO #Expected
FROM #Actual;
---------------------------------------------------------------------------------------------------------
--tie
--tSQLt: INSERT INTO #Expected [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
INSERT INTO #Expected
VALUES($CURSOR$);
---------------------------------------------------------------------------------------------------------
--tca
--tSQLt: SELECT INTO #Actual; [tSQLt - Database Unit Testing for SQL Server. Get it at http://tsqlt.org]
SELECT *
INTO #Actual
FROM $CURSOR$;
---------------------------------------------------------------------------------------------------------