SQL Server
Results into a SQL Server table, or through a stored procedure — the scripts and what is specific to SQL Server.
When to use it
When results should be kept across runs and reported on — see Database outputs for what every database output does: one row per test as it finishes, columns matched by name, objects created when CAT may. This page has what is specific to SQL Server: the scripts and the procedure form. Both SqlServer@1 and SqlServer@2 data sources can be the target.
How to set it
Data sources:
- Name: DWH
Provider: SqlServer@2
Connection string: "%DWH_CONNECTION_STRING%"
Output:
- Database: DWH
Table: dbo.CatTestResult
or, to call a stored procedure for every result instead of inserting:
Output:
- Database: DWH
Procedure: dbo.SaveCatTestResults
The account needs INSERT on the table, or EXECUTE on the procedure. If the table or procedure does not exist and the account may create it, CAT creates it — the procedure together with a dbo.CatTestResult table.
What it looks like
One row per test, the columns of your table — see the rows of the sample run on Database outputs.
Details
Table
The table CAT creates when asked; create it yourself with this script, renamed, trimmed or extended as you like. Any subset of these columns works; custom columns must be nullable or have a default.
CREATE TABLE [dbo].[CatTestResult]
(
TestResultID INT IDENTITY PRIMARY KEY,
ExecutionGuid UNIQUEIDENTIFIER NOT NULL,
[Project] NVARCHAR(200) NOT NULL,
[FullName] NVARCHAR(700) NOT NULL,
TestResult VARCHAR(30) NOT NULL,
StartedOn DATETIME2 NOT NULL,
FinishedOn DATETIME2 NOT NULL,
[RawMessage] NVARCHAR(MAX) NULL,
[Exception] NVARCHAR(MAX) NULL,
[Description] NVARCHAR(MAX) NULL,
[FirstDataSource] NVARCHAR(200) NOT NULL,
FirstQuery NVARCHAR(MAX) NOT NULL,
SecondDataSource NVARCHAR(200) NULL,
SecondQuery NVARCHAR(MAX) NULL,
Expectation VARCHAR(50) NOT NULL,
[Key] NVARCHAR(200) NULL,
Metadata NVARCHAR(300) NULL,
Tags NVARCHAR(1000) NULL,
Suite NVARCHAR(200) NULL,
TestCase NVARCHAR(200) NULL,
[Order] INT NULL,
[Name] NVARCHAR(300) NULL,
[Timeout] INT NULL,
MaximumErrorsLogged INT NULL,
ThreadNumber INT NOT NULL,
[Message] NVARCHAR(MAX) NULL,
NumberOfErrors INT NULL,
LogNumberOfErrors BIT NULL
);
GO
Stored procedure
A procedure lets the database do more than store the row — log elsewhere, start a process when a given test fails. The parameters CAT passes are matched by name (optionally with the prefix C_) and any subset is fine: CAT reads the procedure’s parameters before the run and passes only those.
CREATE PROCEDURE dbo.SaveCatTestResults
(
@ExecutionGuid UNIQUEIDENTIFIER,
@Project NVARCHAR(200),
@FullName NVARCHAR(700),
@TestResult VARCHAR(30),
@StartedOn DATETIME2,
@FinishedOn DATETIME2,
@RawMessage NVARCHAR(MAX),
@Exception NVARCHAR(MAX),
@Description NVARCHAR(MAX),
@FirstDataSource NVARCHAR(200),
@FirstQuery NVARCHAR(MAX),
@SecondDataSource NVARCHAR(200),
@SecondQuery NVARCHAR(MAX),
@Expectation VARCHAR(50),
@Key NVARCHAR(200),
@Metadata NVARCHAR(300),
@Tags NVARCHAR(1000),
@Suite NVARCHAR(200),
@TestCase NVARCHAR(200),
@Order INT,
@Name NVARCHAR(300),
@Timeout INT,
@MaximumErrorsLogged INT,
@ThreadNumber INT,
@Message NVARCHAR(MAX),
@NumberOfErrors INT,
@LogNumberOfErrors BIT
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [dbo].[CatTestResult]
(
ExecutionGuid, Project, FullName, TestResult, StartedOn, FinishedOn, RawMessage, Exception, Description,
FirstDataSource, FirstQuery, SecondDataSource, SecondQuery, Expectation,
[Key], [Metadata], [Tags], Suite, TestCase, [Order], [Name],
[Timeout], MaximumErrorsLogged, ThreadNumber, [Message], NumberOfErrors, LogNumberOfErrors
)
VALUES
(
@ExecutionGuid, @Project, @FullName, @TestResult, @StartedOn, @FinishedOn, @RawMessage, @Exception, @Description,
@FirstDataSource, @FirstQuery, @SecondDataSource, @SecondQuery, @Expectation,
@Key, @Metadata, @Tags, @Suite, @TestCase, @Order, @Name,
@Timeout, @MaximumErrorsLogged, @ThreadNumber, @Message, @NumberOfErrors, @LogNumberOfErrors
);
END
GO
Specifics
- Each thread of the run holds its own connection; results are written as the tests finish.
StartedOnandFinishedOnareDATETIME2, UTC.Message,RawMessage,Exceptionand the queries areNVARCHAR(MAX).
Related
- Database outputs — the shared mechanics.
- Properties — the column names CAT recognizes.
- SqlServer@2 — the data source.