Skip to content

Commit 56d0f86

Browse files
authored
Merge pull request #184 from tSQLt-org/github-pages
GitHub pages pulling latest from github-pages branch
2 parents a8e436d + d0a4c12 commit 56d0f86

24 files changed

+1314
-3
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These owners will be the default owners for everything in
2+
# the repo. Unless a later match takes precedence,
3+
# @global-owner1 and @global-owner2 will be requested for
4+
# review when someone opens a pull request.
5+
* @tsqlt-org/maintainers

docs/_config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
theme: jekyll-theme-dinky
22
title: tSQLt - Database Unit Testing for SQL Server
3-
description: tSQLt is the open source framework for unit testing on SQL Server
3+
description: tSQLt is the open source framework for unit testing on SQL Server
4+
defaults:
5+
-
6+
scope:
7+
path: ""
8+
values:
9+
layout: "default"

docs/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
---
2-
layout: default
32
---
4-
53
WELCOME TO TSQLT, THE OPEN SOURCE DATABASE UNIT TESTING FRAMEWORK FOR SQL SERVER
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# AssertEmptyTable
2+
3+
## Syntax
4+
5+
``` sql
6+
tSQLt.AssertEmptyTable [@TableName = ] 'name of table to be checked' [, [@Message = ] 'message' ]
7+
```
8+
9+
## Arguments
10+
11+
[**@TableName** = ] name of table to be checked
12+
13+
The name of a table which is expected to be empty. @Expected is NVARCHAR(MAX) with no default.
14+
15+
[**@Message** = ] ‘message’
16+
17+
Optional. String containing an additional failure message to be used if the expected and actual values are not equal. @Message is NVARCHAR(MAX) with a default of ‘unexpected/missing resultset rows!’.
18+
19+
## Return Code Values
20+
21+
Returns 0
22+
23+
## Errors Raised
24+
25+
Raises a `failure` error if the table contains any rows.
26+
27+
## Result Sets
28+
None
29+
30+
## Overview
31+
32+
AssertEmptyTable checks if a table is empty. If the table does contain any rows, the failure message displays all rows found.
33+
34+
## Examples
35+
36+
Example: AssertEqualsTable to check the results of a view
37+
This test case uses AssertEqualsTable to compare the data returned by a view to an expected data set.
38+
39+
``` sql
40+
CREATE PROCEDURE testFinancialApp.[test that Report generates no rows if base tables are empty]
41+
AS
42+
BEGIN
43+
IF OBJECT_ID('actual') IS NOT NULL DROP TABLE actual;
44+
45+
------Fake Table
46+
EXEC tSQLt.FakeTable 'FinancialApp', 'CurrencyConversion';
47+
EXEC tSQLt.FakeTable 'FinancialApp', 'Sales';
48+
49+
------Execution
50+
SELECT amount, currency, customerId, employeeId, itemId, date
51+
INTO actual
52+
FROM FinancialApp.Report('USD');
53+
54+
------Assertion
55+
EXEC tSQLt.AssertEmptyTable 'actual';
56+
END;
57+
GO
58+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# AssertEquals
2+
3+
## Syntax
4+
5+
``` sql
6+
tSQLt.AssertEquals [@expected = ] expected value, [@actual = ] actual value[, [@message = ] 'message' ]
7+
```
8+
9+
## Arguments
10+
[**@Expected** = ] expected value
11+
12+
The expected value for the test. @Expected is SQL_VARIANT with no default.
13+
14+
[**@Actual** = ] actual value
15+
16+
The actual value resulting from processing during the test. @Actual is SQL_VARIANT with no default.
17+
18+
[**@Message** = ] ‘message’
19+
20+
Optional. String containing an additional failure message to be used if the expected and actual values are not equal. @Message is NVARCHAR(MAX) with no default.
21+
22+
## Return Code Values
23+
Returns 0
24+
25+
## Error Raised
26+
Raises a `failure` error if expected and actual are not equal.
27+
28+
Raises an `Operand type clash` error if the value passed for @Expected or @Actual is not compatible with SQL_VARIANT. The most common form of this is VARCHAR(MAX) – for this `tSQLt.AssertEqualsString` is provided.
29+
30+
## Result Sets
31+
None
32+
33+
## Overview
34+
`tSQLt.AssertEquals` compares two values for equality. If they are not equal, the test case is failed; otherwise, `tSQLt.AssertEquals` does not affect test processing. For the purposes of `tSQLt.AssertEquals`, NULL is considered equal to NULL. Any non-NULL value is considered not equal to NULL.
35+
36+
## Examples
37+
### Example: `tSQLt.AssertEquals` to check the results of a function
38+
This test case uses `tSQLt.AssertEquals` to compare the return result of a function with an expected value.
39+
40+
``` sql
41+
CREATE PROCEDURE testFinancialApp.[test that ConvertCurrencyUsingLookup converts using conversion rate in CurrencyConversion table]
42+
AS
43+
BEGIN
44+
DECLARE @expected MONEY; SET @expected = 3.2;
45+
DECLARE @actual MONEY;
46+
DECLARE @amount MONEY; SET @amount = 2.00;
47+
DECLARE @sourceCurrency CHAR(3); SET @sourceCurrency = 'EUR';
48+
DECLARE @destCurrency CHAR(3); SET @destCurrency = 'USD';
49+
50+
------Fake Table
51+
EXEC tSQLt.FakeTable 'FinancialApp', 'CurrencyConversion';
52+
53+
INSERT INTO FinancialApp.CurrencyConversion (id, SourceCurrency, DestCurrency, ConversionRate)
54+
VALUES (1, @sourceCurrency, @destCurrency, 1.6);
55+
------Execution
56+
SELECT @actual = amount FROM FinancialApp.ConvertCurrencyUsingLookup(@sourceCurrency, @destCurrency, @amount);
57+
58+
------Assertion
59+
EXEC tSQLt.assertEquals @expected, @actual;
60+
END;
61+
GO
62+
```
63+
64+
### Example: A variety of the possibilities of `tSQLt.AssertEquals`
65+
66+
The examples below show what to expect from AssertEquals when called with different values.
67+
68+
``` sql
69+
EXEC tSQLt.AssertEquals 12345.6789, 12345.6789; -- pass
70+
EXEC tSQLt.AssertEquals 'hello', 'hello'; -- pass
71+
EXEC tSQLt.AssertEquals N'hello', N'hello'; -- pass
72+
73+
DECLARE @datetime DATETIME; SET @datetime = CAST('12-13-2005' AS DATETIME);
74+
EXEC tSQLt.AssertEquals @datetime, @datetime; -- pass
75+
76+
DECLARE @bit BIT; SET @bit = CAST(1 AS BIT);
77+
EXEC tSQLt.AssertEquals @bit, @bit; -- pass
78+
79+
EXEC tSQLt.AssertEquals NULL, NULL; -- pass
80+
EXEC tSQLt.AssertEquals 17, NULL; -- fail
81+
EXEC tSQLt.AssertEquals NULL, 17; -- fail
82+
83+
EXEC tSQLt.AssertEquals 12345.6789, 54321.123; -- fail
84+
EXEC tSQLt.AssertEquals 'hello', 'goodbye'; -- fail
85+
86+
DECLARE @datetime1 DATETIME; SET @datetime1 = CAST('12-13-2005' AS DATETIME);
87+
DECLARE @datetime2 DATETIME; SET @datetime2 = CAST('07-19-2005' AS DATETIME);
88+
EXEC tSQLt.AssertEquals @datetime1, @datetime2; -- fail
89+
90+
DECLARE @bit1 BIT; SET @bit1 = CAST(1 AS BIT);
91+
DECLARE @bit2 BIT; SET @bit2 = CAST(1 AS BIT);
92+
EXEC tSQLt.AssertEquals @bit1, @bit2; -- pass
93+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# AssertEqualsString
2+
3+
## Syntax
4+
5+
``` sql
6+
tSQLt.AssertEqualsString [@expected = ] expected value
7+
, [@actual = ] actual value
8+
[, [@message = ] 'message' ]
9+
```
10+
11+
## Arguments
12+
[**@Expected** = ] expected value
13+
14+
The expected value for the test. @Expected is NVARCHAR(MAX) with no default.
15+
16+
[**@Actual** = ] actual value
17+
18+
The actual value resulting from processing during the test. @Actual is NVARCHAR(MAX) with no default.
19+
20+
[**@Message** = ] ‘message’
21+
22+
Optional. String containing an additional failure message to be used if the expected and actual values are not equal. @Message is NVARCHAR(MAX) with no default.
23+
24+
## Return Code Values
25+
Returns 0
26+
27+
## Error Raised
28+
Raises a `failure` error if expected and actual are not equal.
29+
30+
## Result Sets
31+
None
32+
33+
## Overview
34+
`tSQLt.AssertEqualsString` compares two string values for equality. If they are not equal, the test case is failed; otherwise, `tSQLt.AssertEqualsString` does not affect test processing. For the purposes of `tSQLt.AssertEqualsString`, NULL is considered equal to NULL. Any non-NULL value is considered not equal to NULL.
35+
36+
## Examples
37+
### Example: AssertEqualsString to check the results of a function
38+
This test case uses AssertEqualsString to compare the return result of a function with an expected value. The function formats a first and last name into a standard string for display.
39+
40+
``` sql
41+
CREATE PROC TestPerson.[test FormatName concatenates names correctly]
42+
AS
43+
BEGIN
44+
DECLARE @expected NVARCHAR(MAX); SET @expected = 'Smith, John';
45+
DECLARE @actual NVARCHAR(MAX);
46+
47+
SELECT @actual = person.FormatName('John', 'Smith');
48+
49+
EXEC tSQLt.AssertEqualsString @expected, @actual;
50+
END;
51+
```
52+
53+
### Example: A variety of the possibilities of AssertEqualsString
54+
55+
The examples below show what to expect from AssertEqualsString when called with different values.
56+
57+
``` sql
58+
EXEC tSQLt.AssertEqualsString 'hello', 'hello'; -- pass
59+
EXEC tSQLt.AssertEqualsString N'goodbye', N'goodbye'; -- pass
60+
EXEC tSQLt.AssertEqualsString 'hello', N'hello'; - pass (values are compared as NVARCHAR(MAX)
61+
62+
EXEC tSQLt.AssertEqualsString 'hello', NULL; -- fail
63+
EXEC tSQLt.AssertEqualsString NULL, 'hello'; -- fail
64+
EXEC tSQLt.AssertEqualsString NULL, NULL; -- pass
65+
```
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# AssertEqualsTable
2+
3+
## Syntax
4+
5+
``` sql
6+
tSQLt.AssertEqualsTable [@Expected = ] 'expected table name'
7+
, [@Actual = ] 'actual table name'
8+
[, [@FailMsg = ] 'message' ]
9+
```
10+
11+
## Arguments
12+
[**@Expected** = ] expected table name
13+
14+
The name of a table which contains the expected results for the test. @Expected is NVARCHAR(MAX) with no default.
15+
16+
[**@Actual** = ] actual table name
17+
18+
The name of a table which contains the results from processing during the test. @Actual is NVARCHAR(MAX) with no default.
19+
20+
[**@FailMsg** = ] ‘message’
21+
22+
Optional. String containing an additional failure message to be used if the expected and actual values are not equal. @FailMsg is NVARCHAR(MAX) with a default of ‘unexpected/missing resultset rows!’.
23+
24+
## Return Code Values
25+
Returns 0
26+
27+
## Errors Raised
28+
Raises a `failure` error if the contents of the expected table and the actual table are not equal.
29+
30+
Certain datatypes cannot be compared with `tSQLt.AssertEqualsTable`. If the tables being compared contain an unsupported datatype, the following error will be raised:
31+
32+
> The table contains a datatype that is not supported for `tSQLt.AssertEqualsTable`.
33+
34+
The following datatypes are known to be unsupported by `tSQLt.AssertEqualsTable`: text, ntext, image, xml, geography, geometry, rowversion and CLR datatypes that are not marked comparable and byte ordered.
35+
36+
## Result Sets
37+
None
38+
39+
## Overvoew
40+
`tSQLt.AssertEqualsTable` compares the contents of two tables for equality. It does this by comparing each row of the tables for an exact match on all columns. If the tables do not contain the same data, the failure message displays which rows could not be matched.
41+
42+
## Examples
43+
### Example: AssertEqualsTable to check the results of a view
44+
This test case uses AssertEqualsTable to compare the data returned by a view to an expected data set.
45+
46+
``` sql
47+
CREATE PROCEDURE testFinancialApp.[test that Report gets sales data with converted currency]
48+
AS
49+
BEGIN
50+
IF OBJECT_ID('actual') IS NOT NULL DROP TABLE actual;
51+
IF OBJECT_ID('expected') IS NOT NULL DROP TABLE expected;
52+
53+
------Fake Table
54+
EXEC tSQLt.FakeTable 'FinancialApp', 'CurrencyConversion';
55+
EXEC tSQLt.FakeTable 'FinancialApp', 'Sales';
56+
57+
INSERT INTO FinancialApp.CurrencyConversion (id, SourceCurrency, DestCurrency, ConversionRate)
58+
VALUES (1, 'EUR', 'USD', 1.6);
59+
INSERT INTO FinancialApp.CurrencyConversion (id, SourceCurrency, DestCurrency, ConversionRate)
60+
VALUES (2, 'GBP', 'USD', 1.2);
61+
62+
INSERT INTO FinancialApp.Sales (id, amount, currency, customerId, employeeId, itemId, date)
63+
VALUES (1, '1050.00', 'GBP', 1000, 7, 34, '1/1/2007');
64+
INSERT INTO FinancialApp.Sales (id, amount, currency, customerId, employeeId, itemId, date)
65+
VALUES (2, '4500.00', 'EUR', 2000, 19, 24, '1/1/2008');
66+
67+
------Execution
68+
SELECT amount, currency, customerId, employeeId, itemId, date
69+
INTO actual
70+
FROM FinancialApp.Report('USD');
71+
72+
------Assertion
73+
CREATE TABLE expected (
74+
amount MONEY,
75+
currency CHAR(3),
76+
customerId INT,
77+
employeeId INT,
78+
itemId INT,
79+
date DATETIME
80+
);
81+
82+
INSERT INTO expected (amount, currency, customerId, employeeId, itemId, date) SELECT 1260.00, 'USD', 1000, 7, 34, '2007-01-01';
83+
INSERT INTO expected (amount, currency, customerId, employeeId, itemId, date) SELECT 7200.00, 'USD', 2000, 19, 24, '2008-01-01';
84+
85+
EXEC tSQLt.AssertEqualsTable 'expected', 'actual';
86+
END;
87+
GO
88+
```
89+
90+
## Understanding The Output
91+
When the two tables being compared contain different data, the results are displayed as a text table in the failure message. The first column of this text table (\_m\_) describes the result of the comparison. The symbol “<” indicates that the row was found in the Expected table but did not match anything in the Actual table. The symbol “>” indicates that the row was found in the Actual table but not in the Expected table. Finally, the symbol “=” indicates that the row was matched between the Expected and Actual tables.
92+
93+
For example, consider the following Expected and Actual tables:
94+
95+
Expected
96+
|col1|col2|col3|
97+
|---|---|---|
98+
|1|A|a|
99+
|2|B|b|
100+
|3|C|c|
101+
102+
Actual
103+
|col1|col2|col3|
104+
|---|---|---|
105+
|1|A|a|
106+
|3|X|c|
107+
108+
These tables would result in the following failure message:
109+
110+
111+
`failed: unexpected/missing resultset rows!`
112+
|_m_|col1|col2|col3|
113+
|---|---|---|---|
114+
|< |2 |B |b |
115+
|< |3 |C |c |
116+
|= |1 |A |a |
117+
|> |3 |X |c |

0 commit comments

Comments
 (0)