Questions tagged [tsqlt]
tSQLt – The Database Unit Testing Framework for SQL Server
195
questions
0
votes
0
answers
26
views
tSQLt testing between source and destination database
I have data loaded from Oracle DB to SQL Server every day via SSIS job. I have asked to verify in tSQLt whether a number of records on oracle DB loaded correctly in SQL Server. How can I do this ...
0
votes
2
answers
55
views
Exec tSQLt.Faketable crashing our original table constraint and data
During debugging the tsqlt code, I have directly run the below statement without wrapping it as sp and my original table constraint got deleted and some data missing from the original table.
Exec ...
0
votes
1
answer
48
views
tSQLt V1.0.8083.3529 will not build in Visual Studio 2022
I have a database test project and tSQLt has an error when I do a build:
SQL71501: View: [tSQLt].[Private_HostPlatform] has an unresolved reference to object [sys].[dm_os_host_info].[host_platform].
...
0
votes
0
answers
28
views
My tSQLt scripts gets overwritten when prod db refresh happens? How to persist the tsqlt script?
I have tsqlt installed on lower environments and I have created my tsqlt for the unit testing. But right now, we don't promote tSQLt to production since we are not allowed to install tSQLt in ...
0
votes
1
answer
24
views
does tSQLt support comparing two JSON strings?
I am using tSQLt to test stored procedures which output JSON string results. The problem I have is that the key/value pairs in JSON are not always the same order. For example,
JSON1: {"A":1, ...
0
votes
0
answers
22
views
Does tSQLT needed the database should set TRUSTWORTHY ON?
Is database TRUSTWORTHY ON necessary for tSQLt to run? In our DB environment, we can't set TRUSTWORTHY ON for databases.
Does tSqlt run with the database status of TRUSTWORTHY OFF?
0
votes
0
answers
62
views
Can tsqlt table accessed outside of tSqlt scope?
I am writing a tsqlt unit testing where I am not faking the table and I am using the real SQL table ex:sendEmail to test the email sending functionality.
I am inserting the value like below from tsqlt ...
0
votes
0
answers
53
views
How to use setup procedure in tSQLt?
I have 5 test cases and 5 test cases are separately called the same stored procedure. Can I use setup stored procedure for this purpose? I couldn't understand the setup stored procedure in tsqlt with ...
1
vote
1
answer
119
views
How can I use a case statement that includes a wildcard
I have tried to include a wildcard in the below Case statement with no good result.
CASE
WHEN store IS NULL THEN
(
CASE
WHEN location IN (‘A%’, ‘B%’’ ‘C%’) ...
0
votes
1
answer
87
views
What order the test cases run in the tSQLt?
I have 30 test cases in the 'EmployeeSchema'. I want to know in which order the test cases run in the tSqlt? If I know the order of execution of test cases, then I alter the execution order of my test ...
0
votes
1
answer
62
views
tSQLt.AssertEqualsTable takes hours to complete when big data set involves
EXEC tSQLt.AssertEqualsTable 'expected', 'actual';
I am comparing expected vs actual tables. This table has 100k plus records and if 80k records match 20k records don't match then tsqlt will paint ...
0
votes
1
answer
42
views
Unit Testing Case Statements
I appreciate this probably isn't the place to ask, if there is a better place please let me know.
I have a legacy Stored Procedure that selects some data and inserts into a table. However there are ...
1
vote
0
answers
30
views
tSQLt.Fail does not make test fail
I created a test like this:
CREATE PROCEDURE MyTestClass.[test example01] AS
BEGIN
EXEC tSQLt.Fail 'Not implemented';
END;
However, when I run the test the result is Success. What am I doing ...
1
vote
2
answers
66
views
How to use tSQLt to test if a integer value is within a specific range?
I'm using the tSQLt unit testing tool. I want to test if an actual row count is within .1% of an expected value. Seems like I could use a EXEC tSQLt.AssertIntValueInRange procedure, but I couldn't ...
0
votes
1
answer
63
views
Mock SERVERPROPERTY in tSQLt
I am writing some logic that has branches based on the SQL Server version. Is there a way to mock SERVERPROPERTY in tSQLt?
Edit: Updated question and description with correct function name.
1
vote
1
answer
114
views
Using tSQLt AssertEqualsTableSchema in a test procedure that contains TRY/CATCH
It seems that the SQL test framework tSQLt does not allow to use an assertion such as tSQLt.AssertEqualsTableSchema after a TRY/CATCH block that generates an error. If I try that, the test generates ...
0
votes
1
answer
259
views
How to fix this error: Msg 50000, Level 17, State 2, Procedure tSQLt.FakeTable, Line 13 [Batch Start Line 0] Please run this inside a unit test
I am currently working on my SQL Server project unit testing using TSQLT and I'm getting the below error, and don't know how to fix it.
Has anyone faced it before? Can anyone suggest a tutorial for ...
0
votes
0
answers
118
views
tSQLt failure when attempting to SpyProcedure a synonym SP
I am new to tSQLt. I am writing a test for a stored procedure that calls an sp on a different DB. This external SP is set as a synonym in the DB I use. To enhance, this is what I have:
SP1 on DB1
SP2 ...
0
votes
1
answer
49
views
How Does FakeTable Work with the COLUMNS_UPDATED() function?
I have a 300+ column table and a trigger.
I have 40(ish) "columns of interest" and the rest I don't care about.
The purpose of the trigger is to determine if any of the "columns of ...
0
votes
1
answer
82
views
committing both live code and tsqlt tests
My company has recently started using tSQLt to test our codebase. We've built a few good test suites and now we're trying to figure out the best way to commit them.
We're using an SQL server with ...
0
votes
0
answers
24
views
tSQLt.AssertEqualsTable order mismatch error
i am try to run one test, I got below error, So can you guys pls help me on this to fix this?
pub_id
avg_price
0736
9.784
0877
15.41
1389
18.976
ALL
14.7662
CREATE PROCEDURE ...
0
votes
1
answer
83
views
tsqlt spyProcedure with multiple output parameters
There is a related post to my question dealing with a single output parameter, but I cannot find a way to apply that to my procedure which has multiple output parameters.
An overview of the procedure ...
0
votes
1
answer
120
views
How does one handle scope identity statements in T-SQL T?
There doesn't seem to be any way to Fake a table then have the SCOPE_IDENTITY function run on the faked table.
Take this statement (inside a stored procedure)
INSERT INTO [dbo].[SomeTable](Id1, Id2)
...
3
votes
1
answer
251
views
Publishing test results to Azure (VS Database Project, tSQLt, Azure Pipelines, Docker)
I am trying to fully automate the build, test, and release of a database project using Azure Pipeline.
I already have a Visual Studio solution which consists of three database projects. The first ...
1
vote
2
answers
501
views
Create a temporary table dynamically from calling an stored procedure
I want to create a temporary table from calling a stored procedure as something like below
Select *
into #temp1
from
exec sp1;
or
select *
into #temp1
from sys....
0
votes
2
answers
73
views
TSQLT Asserting stored procedure column names
Is there a way for tsqlt to assert all the columns returned from a stored procedure have a certain column name? I need to check if Employee_lname column actually returns as 'Employee_lname' instead ...
0
votes
0
answers
49
views
Line vs Statement coverage in SQL Cover
I am trying to use SQL Cover library in my project to find the code coverage,
I have tried using Redgate SQL Test previously for same purpose but with SQL cover the number of lines are almost double ...
1
vote
2
answers
85
views
Can I integrate Redgate SQL Test directly with teamcity to get code coverage
I have purchased Redgate SQL Test, I need to integrate same with Teamcity.
Can i achieve it without any other licensed softwares from Redgate.
0
votes
1
answer
57
views
Is there a way to assert a "not" condition using tSQLt?
I am new to using tSQLt and struggling a bit with the available assert functions. The tSQLt.AssertEmptyTable method is great, but how do you apply a "not" condition to this, i.e. I want to ...
1
vote
0
answers
180
views
Code coverage of SQL unit testing with tSQLt tool and integrating in Sonarqube dashboard
We're using tSQLt for SQL unit test cases and integrated with Azure DevOps for build pipeline using Redgate SQL Change Automation:build task.
Now I got result as "TestResults.junit.xml" and ...
0
votes
1
answer
103
views
tSQLt testing isnt working while my teachers is
For school we are working on tests for a project. The test my teacher gave me works with no problem:
EXEC tSQLt.NewTestClass 'testMaxPresidents1';
GO
CREATE PROCEDURE [testMaxPresidents1].[test die ...
0
votes
3
answers
175
views
Get missing columns from a list of expected columns in a table
The test has a list of expected columns which verifies if the actual table has them. The assertion is if the counts are equal in expected and actual, then all columns are present.
How to extract which ...
0
votes
3
answers
641
views
How to view test results in tSQLt?
We are using tSQLt for unit testing our database and executed below:
EXEC tSQLt.Run '[testComplianceDimensions].[test CountOfPropertiesWithLatestRepairJob]'
EXEC tSQLt.Run '[testComplianceDimensions].[...
0
votes
1
answer
28
views
tSQLt.run does nothing in one Query window but works in another
I have created 3 test classes.
I can, from one query window run the following for all test classes.
tSQLt.Run 'class1';
tSQLt.Run 'class2';
tSQLt.run 'class3';
But from all other query window, the ...
0
votes
2
answers
119
views
tSQLt.ExceptException is not working with rollback transaction in SQL Server
Below is my code snippet of a test case for a stored procedure my_proc to check not null parameter passed to the stored procedure.
--faking required tables here
--set values of parameters to be ...
0
votes
1
answer
345
views
Integration of tSQLt + SSDT into Jenkins
I am using SQL Server 2017 and Visual Studio 2019 Community edition.
I have created my first SSDT project and configured it in Jenkins and I am facing issues while deploying it before running my tSQLt ...
0
votes
1
answer
102
views
tsqlt FakeTable not rolling back after unit test executed
I have an extremely simple unit test where I am testing the functionality of a tsqlt.FakeTable. However, after running the command and inserting data, it does not roll back to the previous state.
...
2
votes
1
answer
531
views
Using TSQLT FakeTable to test a table created by a Stored Procedure
I am learning to write unit tests for work. I was advised to use TSQLT FakeTable to test some aspects of a table created by a stored procedure.
In other unit tests, we create a temp table for the ...
0
votes
2
answers
165
views
tsqlt testing an output parameter from a stored procedure
I have a stored procedure that I am trying test for the proper generation of an output parameter. I experimented with tsqlt.ExpectException, but that did not work. I instead am trying tsqlt....
0
votes
1
answer
189
views
Must declare scalar variable in a unit test
I am trying to design a unit test that ensures that a message is bigger than a certain number of characters. My code is:
EXEC tSQLt.NewTestClass 'TestMarketingEnoughRows';
GO
CREATE OR ALTER ...
0
votes
2
answers
555
views
TSQLT - Error while trying to fake a table
Hi I am pretty new for TSQLT Unit tests I am getting error while trying to create a fake table, any help is appreciated.
I have my dev project in one database and TSQLT in another database
EXEC ...
0
votes
1
answer
200
views
TSQLT Database Unit test
I am trying to hands on with TSQLT unittest framework for first time and have come across a problem. I have a stored proc like this which returns some numbers
Use Mydatabase
Declare @parameter1, @...
0
votes
1
answer
54
views
tSQLt - Error 'Could not find method 'SigningKey' for type 'tSQLtCLR.tSQLtPrivate' in assembly 'tSQLtCLR''
We are moving Jenkins to a new server which has SQL Server 2019 installed.
Jenkins was previously running on a server that used SQL Server 2008 R2 (and the build process worked flawlessly)
We use ...
1
vote
1
answer
353
views
tSQLt.XmlResultFormatter truncates results after 2033 chars
Trying to export my tSQLt test results to XML with tSQLt.XmlResultFormatter.
But it seems to truncate the output after 2033 characters,
BEGIN TRY EXEC tSQLt.RunAll END TRY BEGIN CATCH END CATCH; ...
0
votes
1
answer
119
views
tSQLt unit test hanging and giving a 'A severe error happened during test execution. Test did not finish.' error?
When I run a unit test in tSQLt, the procedure just hangs in executing state. The unit test only contains a single stored procedure.
When I run the stored procedure directly, it executes successfully....
9
votes
1
answer
214
views
Running tSQLt project from sources fails on the due to the Public Token mismatch
I'm trying to do some improvements for tSQLt framework and I'm mostly finish, but can't do that as few tests related to the certificate I wasn't touching are still failing:
[exec] |18|[...
2
votes
1
answer
224
views
Programmatically generate DDL statement for User Defined Data Type (UDDT)
I'm trying to add faking synonyms pointing to remote objects support(PR) for tSQLt.
To make it possible to mock/fake tables that have user defined system types in the table definitions, I need to ...
1
vote
2
answers
70
views
user defined data types allowed in testing views?
I'm using tsqlt to test a view -- OrderHeader, which joins OrderHeader with OrderState. In a set up procedure I create fake tables for those two tables, and insert rows. The table defs and user ...
-2
votes
2
answers
336
views
tSQLt test cases for database insert and update via stored procedures
I want to write tSQLt test cases for database insert and update via stored procedures.
I followed the official documentation of tSQLt and installed CLR into the database.
I can see multiple tables ...
0
votes
1
answer
249
views
Cannot import the following key file: tSQLtOfficialSigningKey.pfx when running building tSLQt
I am trying to run tSQLt solution locally by following instructions in the tSQLt\Build\Install the tSQLt build.docx.
Re-built tSQLtCLR solution:
1>------ Rebuild All started: Project: tSQLtCLR, ...