tSQLt

Unit Testing Databases with tSQLt Part 12 – Unit Testing Views

30 October 2012

In Part 11, we delved into mocking stored procedures and explored how to populate output parameters or add a row to a table when faking a procedure. In this post, we will look at views, including writing tests against the views themselves and also how to mock a view that another object under test depends […]

Read the full article →

A mock too far? What is good practice for mocking database objects with tSQLt?

28 March 2012

tSQLt, the open source unit testing framework for SQL2005+ has some really great features that allow database objects to be mocked, dramatically reducing the time needed to set up reference data for each test.  But sometimes, just because you can do something doesn’t mean that you should; at least not all the time.  In this […]

Read the full article →

Unit Testing Databases with tSQLt Part 10 – testing a foreign key’s ON DELETE or ON UPDATE actions

20 March 2012

In Part 9, we looked at basic unit testing of a foreign key ensuring that basic referential integrity was properly enforced. In this post, we continue writing tests for foreign keys, delving in to cascading deletes (or not cascading as the case may be). We’re using deletes in this article but the same approach and […]

Read the full article →

Unit Testing Databases with tSQLt Part 9 – testing a FOREIGN KEY constraint

7 March 2012

In Part 8, we looked at testing string searches as part of a WHERE clause and also validating the effect of supplying multiple, cumulative search conditions. In this post, we go back to our DDL tests and explore a couple of approaches to unit testing foreign keys.

Read the full article →

Unit Testing Databases with tSQLt Part 8 – testing string searches in the WHERE clause

16 February 2012

In Part 7, we looked at how to write tests to confirm that parameterised start and end dates were correctly applied in a WHERE clause. In this post we will extend that SELECT procedure further by writing more tests for the WHERE clause, specifically searching the contents of a string, and validating how default values […]

Read the full article →

Unit Testing Databases with tSQLt Part 7 – testing date ranges in a WHERE clause

13 January 2012

In Part 6, we looked at writing tests against a simple SELECT procedure checking that the correct columns were included and that results were returned in the correct order. In this post we will extend that SELECT procedure writing some tests for the WHERE clause, specifically dates and date ranges, and validating how default values […]

Read the full article →

Advanced Database Unit Testing with tSQLt – Testing cross-database tables

20 December 2011

This is the first in an occassional series of articles covering more advanced ways of getting the most out of the tSQLt database unit-testing framework. One of the features of this framework I really like is the ability to fake or mock a table. FakeTable temporarily re-names the “production” table then creates an empty copy […]

Read the full article →

Unit Testing Databases with tSQLt Part 6 – testing a SELECT stored procedure

7 December 2011

In Part 5, we looked at writing tests to prove that one stored procedure calls another and how test-driven development can help us refactor code. In Part 6 we are going to write some initial tests for a stored procedure that returns data as part of the Log4TSql open source logging library for SQL Server 2005+ […]

Read the full article →

Unit Testing Databases with tSQLt Part 5 – testing that a procedure calls another procedure

18 November 2011

In Part 4, we implemented some tests for a simple INSERT procedure with output parameters and wrote the code to pass those tests – ExceptionHandler. In Part 5 we are going to extend ExceptionHandler to collect even more information by calling another stored procedure and use our tests to make sure that ExceptionHandler calls that […]

Read the full article →

Unit Testing Databases with tSQLt Part 4 – testing an INSERT stored procedure

2 November 2011

In Part 3, we completed the tests for the Exception table which will store SQL Server exceptions as part of the Log4TSql framework. In Part 4 we are going to put together some unit tests for the stored procedure that will populate the Exception table. The user stories we are addressing today are “As a […]

Read the full article →