Questions tagged [tsqlt]

tSQLt – The Database Unit Testing Framework for SQL Server

tSQLt is a database unit testing framework for Microsoft SQL Server. tSQLt is compatible with SQL Server 2005 (service pack 2 required) and above on all editions. It is available at tSQLt.org

204 questions
5
votes
4 answers

Using tSQLt, how can I isolate the dependency on the system clock when using GETUTCDATE()?

I have a stored procedure that uses the GETUTCDATE() function several times. It's a very specific line of business sproc, so it probably wouldn't make a lot of sense to show it here. Having said that, it might be helpful to know the sproc will…
pvanhouten
  • 762
  • 10
  • 27
5
votes
4 answers

How do I rename a tSQLt test class?

I'm developing a database using the Red Gate SQL Developer tools. SQL Test, the SSMS add-in that runs tSQLt tests, lacks a way to rename test classes. I have a test called [BackendLayerCustomerAdministrationTests].[test…
Iain Samuel McLean Elder
  • 19,791
  • 12
  • 64
  • 80
5
votes
1 answer

tsqlt error handling trumping stored procedure (unit) error handler

When trying to validate a user supplied GUID within a stored procedure a simple approach was used; take the user input as a CHAR(36) then explicitly CAST it as a UNIQUEIDENTIFIER within a TRY CATCH. The CATCH then bubbles the error with a custom…
Luminary
  • 51
  • 2
4
votes
2 answers

How to Integrating tSQLt tests with Visual Studio Team Services?

I had developed simple Ready Roll database project by following this Getting started with ReadyRoll. After that I added the tSQLt tests in VS2015 using tSQLt adapter by following this Running tests in ReadyRoll with tSQLt Adapter. Next check in my…
Pradeep
  • 5,101
  • 14
  • 68
  • 140
4
votes
3 answers

Is there a way to test other assertions inside a test after calling tSQLt.ExpectException?

Using tSQLt 1.0.5873.27393, I'm trying to write a tSQLt test for a stored procedure that records errors trapped in a CATCH block to a log table before re-throwing the error to the calling session. I can successfully test that the error message is…
Ed Harper
  • 21,127
  • 4
  • 54
  • 80
4
votes
1 answer

code reuse tsqlt / sql test

I am just starting to use tsqlt inside redgate's sql test. I have to deal with quite large tables (large number of columns) in a legacy databases. What is the best practise to insert some fake data into such tables (the 'script as' insert statements…
cs0815
  • 16,751
  • 45
  • 136
  • 299
4
votes
4 answers

tSQLt not running tests

I have an installation that used to work, but now appears not to. Wondering if anyone else has experienced this. Tests that once ran now dont. Nothing appears to run. The output is always as follows: +----------------------+ |Test Execution…
Michael
  • 587
  • 3
  • 14
4
votes
1 answer

How to create default constraint dependent other column in sql server

i have a table like this tab1 create table tab1(ID int identity(1,1), Type varchar(10),IsValued bit) tab1: ID Type IsValued ---------------- 1 S 1 2 R 0 3 R 0 4 S 1 5 S 1 6 R 0 7 S 1 instead of inserting value into…
Ram Das
  • 348
  • 4
  • 15
4
votes
4 answers

tSQLt fails when attempting to FakeTable a synonym table

I am using tSQLt (through Red Gate's SQL Test version 1.0.0.455). tSQLt is installed on database A. I am trying to do a tSQLt.FakeTable on a table in database B on the same SQL server instance through a synonym on database A. Code: ALTER…
steenhulthin
  • 4,553
  • 5
  • 33
  • 52
4
votes
3 answers

How to get MAX int but exclude specific int?

I'd like to get the max integer from a specific column excluding a value that will always be the max if present. Data may look like the following: score, empid 1 3 3 3 10 3 1 5 2 5 1 8 2 8 3 …
4thSpace
  • 43,672
  • 97
  • 296
  • 475
3
votes
1 answer

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 project is the database, which contains the tables,…
BrokenBad
  • 95
  • 6
3
votes
1 answer

tSQLt - How to check if the table values have changed by certain value

In tSQLt, we can compare 2 tables using AssertEqualsTable command. However, is there any way we can assert whether the values in the table have changed by a certain amount? For example: Table A: AccID|Balance Table B: AccID|Balance Is there any way…
variable
  • 8,262
  • 9
  • 95
  • 215
3
votes
1 answer

Why does a tSQLt test pass in Visual Studio Test Explorer when it should fail?

I'm writing some tSQLt tests and running them using Visual Studio's Test Explorer via the tSQLt test adapter extension. I'm doing TDD, so I'm writing the test before writing the stored procedure that it tests. The problem is, when I run the test,…
3
votes
1 answer

Using XACT_ABORT and TRY CATCH together in SQL Server break tSQLt Rollback

I am beginning to work with tSQLt unit tests for SQL Server in my production code. Currently, I use Erland Sommarskog's error handling pattern for SQL Server. USE TempDB; SET ANSI_NULLS, QUOTED_IDENTIFIER ON; GO IF…
3
votes
2 answers

tSQLt: share data between SetUp and tests

I am using tSQLt to unit test t-sql code. Quite often the Arrange part of tests is quite extensive and I am trying to push a lot of it out to the SetUp procedure to reuse among the tests within the class. It would be very useful if Setup and test…
Yuri Makassiouk
  • 425
  • 3
  • 16
1
2
3
13 14