Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test-Driving Your Database

Similar presentations


Presentation on theme: "Test-Driving Your Database"— Presentation transcript:

1 Test-Driving Your Database
Adventures in relational agility @alastairs #tddatabases Who is this guy? Application developer: C# my forté, T-SQL not so much. Not “the database guy” Founder of CSCrafters The last barrier between you and your lunch 

2 Why Bother? Early bug notification Confidence to refactor
Verifiable documentation Ok, but how does it work?

3 Perfect is a verb Make it work, then make it right. Can apply this to our SPROCS and functions with tSQLt Unit testing framework for T-SQL Runs each test in isolation – separate SQL Server transactions Groups tests in schemas (“test classes”) for better organisation and shared setup. - Creating a test class will overwrite it if it already exists Can fake tables and views, and spy on sprocs

4 Recommendations DO test Sprocs Functions Triggers Views Constraints
DON’T test Schema, table structure – brittle tests

5 SPROCS, Constraints Show me teh codez!!!11

6 [Fact] public void Placing_An_Order_Adds_The_Order_To_The_Customers_Account() { // Arrange var customer = new Customer( 1, // Id "Joe", "Bloggs", // Name "10 City Road", "Staines", "Middlesex", "AB1 2CD" // Address ); var order = new Order(1, customer); // Act, Assert: not interesting for this example }

7 [Fact] public void Placing_An_Order_Adds_The_Order_To_The_Customers_Account() { // Arrange var customer = ACustomer() .WithGivenName("Joe") .WithFamilyName("Bloggs") .Build(); var order = new Order(1, customer); // Act, Assert: not interesting for this example }

8 SQL Test Data Builders Show me teh codez!!!11

9 What about CI? A tsqlt runner from a guy called Christian Prieto plus a bunch of sqlcmd calls

10 Questions?


Download ppt "Test-Driving Your Database"

Similar presentations


Ads by Google