Unit Testing in SQL Richard Fennell Engineering Director SqlBits 6 th October 2007.

Slides:



Advertisements
Similar presentations
Black marble the strategic IT asset for your organisation BUT IT WORKS ON MY PC OR CONTINUOUS INTEGRATION TO IMPROVE SOFTWARE QUALITY Richard Fennell Engineering.
Advertisements

Black marble the strategic IT asset for your organisation DEVELOPMENT LIFE CYCLE USING VISUAL STUDIO TEAM EDITION FOR DB PROFESSIONALS Richard Fennell.
Development Life Cycle using Visual Studio Team Edition for DB Professionals Richard Fennell Engineering Director SQLBits II Birmingham 1 st March 2008.
Black marble the strategic IT asset for your organisation MAKING THE SQL DEVELOPER ONE OF THE FAMILY WITH VISUAL STUDIO TEAM SYSTEM Richard Fennell Engineering.
Microsoft Dynamics® AX 2012
Entity Framework Code First Migrations
By: Jose Chinchilla July 31, Jose Chinchilla MCITP: SQL Server 2008, Database Administrator MCTS: SQL Server 2005/2008, Business Intelligence DBA.
Neelesh Kamkolkar Sr. Product Manager/Planner | Microsoft
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
EXTENDING TESTING INTO THE LAB Richard Fennell Engineering Director, Black Marble
Mike Azocar Sr. Developer Technical Specialist Microsoft Corporation
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Cross-curricular Assignment Using your case study…
4/17/2017 7:07 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
#sqlsatPordenone #sqlsat367 February 28, 2015 Testing your databases Alessandro
2 DAT320 Testing and Refactoring Your Database with Visual Studio Team Edition for Database Professionals.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
(code name: Data Dude) Josh Robinson Aculix.
Continuous Integration for Databases Learn how to automate your build and test Steve Jones Red Gate Software Part II of the Continuous Delivery for Databases.
Enterprise Reporting with Reporting Services SQL Server 2005 Donald Farmer Group Program Manager Microsoft Corporation.
Team Foundation Server the answer to all project management problems? Richard Fennell Director.
Cross Platform Mobile Backend with Mobile Services James
Application Lifecycle Management and the cloud
Introduction to SQL 2005 Security Nick Ward SQL Server Specialist Nick Ward SQL Server Specialist
Overview of SQL Server Alka Arora.
Database Unit Testing Team Edition for Database Professionals Sachin Rekhi Program Manager Microsoft Corporation
UNIT TESTING FOR SQL Prepared for SUGSA CodeLabs Alain King Paul Johnson.
Virtualisation of the Test Environment
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
Database Agility Pramod Sadalage ThoughtWorks. © ThoughtWorks, Inc.© Agile.Database:// Introduction The Traditional Database Continuous changes.
Master Data Management & Microsoft Master Data Services Presented By: Jeff Prom Data Architect MCTS - Business Intelligence (2008), Admin (2008), Developer.
Isolated Database Environments Kevin Howell February 2014.
DATABASE DEVELOPMENT WITH VSTS DATABASE EDITION By Chris Dahlberg ©2009 Aspect Software, Inc. All rights reserved. 1.
Unit Testing with FlexUnit
DATABASE DEVELOPMENT WITH VISUAL STUDIO 2010 Chris Dahlberg 1.
Oracle Business Intelligence Foundation – Testing and Deploying OBI Repository.
Confidencial - TRACASA Automatize test [e- Reporting]
SQL SERVER AUDITING. Jean Joseph DBA/Consultant Contact Info: Blog:
Continuous Integration for Databases Steve Jones SQLServerCentral Red Gate Software.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Copyright © New Signature Who we are: Focused on consistently delivering great customer experiences. What we do: We help you transform your business.
1 Punishment Through Continuous Delivery If it hurts, do it more often…
Developing SQL/Server database in Visual Studio Introducing SQL /Server Data Tools Peter Lu.Net Practices Director Principle Architect Nexient March 19.
Copyright 2015 Varigence, Inc. Unit and Integration Testing in SSIS A New Approach Scott @varigence.
Get testing with tSQLt Practical examples and automation Steve Jones SQLServerCentral Red Gate Software.
Automated Build and Test
Introduction ITEC 420.
Building Enterprise Applications Using Visual Studio®
SQL Compare & SQL Refactor
Making Your List and Checking It Twice
Introduction to unit and integration testing with tSQLt
Automated Code Coverage Analysis
SQL Server Data Tools Gert Drapers
Continuous Integration For Databases
Prove to your boss your database is sound - Unit Testing with tSQLt
Intro to Unit Testing with tSQLt
Batches, Transactions, & Errors
12/9/ :15 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
DAT381 Team Development with SQL Server 2005
Batches, Transactions, & Errors
SSDT and Database Project Basics
Module 10: Implementing Managed Code in the Database
Introduction to VSTS Database Professional
Chapter 11 Managing Databases with SQL Server 2000
Your Data Any Place, Any Time
Windows Forms in Visual Studio 2005: An in-depth look at key features
Samir Behara, Senior Developer, EBSCO
Presentation transcript:

Unit Testing in SQL Richard Fennell Engineering Director SqlBits 6 th October 2007

Agenda Unit testing 101 Why test DBs Testing with TSQLUnit Testing in DataDude

Unit Testing 101 Unit testing is a procedure used to validate that individual units of source code are working properly Ideally, each test case is independent from the others Mock objects and test harnesses can be used to assist testing a module in isolation. Unit testing is typically done by developers and not by end-users.

Unit Testing 101 namespace bank { using NUnit.Framework; [TestFixture] public class AccountTest { [Test] public void TransferFunds() { Account source = new Account(); source.Deposit(200.00F); Account destination = new Account(); destination.Deposit(150.00F); source.TransferFunds(destination, F); Assert.AreEqual(250.00F, destination.Balance); Assert.AreEqual(100.00F, source.Balance); }

Unit Testing 101 Unit tests should be quick to run and run often. Unit testing can be the basis of automated testing such as night builds They are normally applied to programming languages such as Java and C#.

Why Test DBs? Mission-critical business functionality in DB Support for evolutionary development Current approaches aren't sufficient (you miss bugs) Why not use a mock object?

Where can we test DBs?

Common DB Testing Methods Combination of PRINT statements and ad-hoc tests with the SQL Query Analyzer when developing stored procedures. T-SQL debugger to inspect the values of variables. In all cases, human judgment is required to analyze the results. As test are ad-hoc, the tests can not easily be repeated again.

Possible Types of Database Unit Test Feature Test – E.g. Testing Stored Procedures Schema Tests – E.g. Returns the columns values you expect Security Tests – E.g. Test who can see what Stock-data Tests – E.g. Check all seed data is present

Testing with TSQLUnit

TSQLUnit A framework to write tests for applications written in Transact-SQL In the tradition of the "xUnit" framework developed by Henrik Ekelund. Open Source, licensed under the LGPL license

Using TSQLUnit Run the install SQL script on a DB Create a stored procedure with a name that starts with ut and underscore, such as ut_testSomething Code a test, then call tsu_failure if the test fails Execute tsu_runTests, it runs the test you have made and shows the result.

Using TSQLUnit CREATE PROCEDURE ut_testCapitalize AS BEGIN VARCHAR(500) EXEC capitalize 'a OUT IF <> ASCII('A')) IS NULL EXEC tsu_failure 'Capitalize should make the first character uppercase' END

Other features TestSuites – Groups similar tests together – tsu_runTests 'capitalizeTests' Fixtures – Many tests needs to have quite a lot of prepared data as a background. – To add a fixture create a stored procedure called ut_capitalizeTests_setup – To explicitly clean up you can make a stored procedure called ut_capitalizeTests_teardown

demo demo TSQLUnit

Testing in Visual Studio for Database Professionals DataDude

Visual Studio Team System Application Life Cycle Management (ALM) Solution

DataDude support the full Database Lifecycle Schema Import Manage Schema Compare with external DB Associated changes with work items Run testsDeploy

Testing in Visual Studio 2008 Firstly remember that can test any CLR code before loading it into SQL Server DataDude adds database tests that can be used to test any stored procedure, function, trigger or DB object A single test project can contain a variety of test types Can be used to auto generate test stubs

demo demo Visual Studio Testing

Managing Database State How do I guarantee that the data in my database is what I expect it to be when I run my tests? – First, you must ensure that the database has the expected state, before you run a collection of tests. – Second, you must ensure that the database has the appropriate state between each test in the test run.

Managing Database State Use a data-generation tool to set the database state, before you run your collection of unit tests Restore a database from backup, or attach an existing database Have your tests assume no state and, as part of each pre-test, set up the appropriate state Manually cleaning up state changes in each post- test script Use Transaction Rollback

Test Data Generation Options Use production data for testing purposes Come up with test data from scratch Configurable data generators – Smart default assignment of generators – Data generation is repeatable – Enforcement of table ratios

demo demo Data Generation & Deploy

Other cool features of DataDude Refactoring DB /deployment Source control

Summary There is no excuse for NOT testing DB objects like any other piece of code. Tools exist to help generate and run tests Tools exist to help generate and manage test data and deployment Make use of them to improve your system quality

Good Resources Microsoft Visual Studio Team System Virtual Labs – Cameron Skinner (Product Unit Manager Visual Studio Team Edition for Database) – h ttp://blogs.msdn.com/camerons Roy Osherove (Blog on TFS, Agile and Testing) –

For Further Information My random thoughts But it works on my PC! You can also get in touch via: – WebSite –