XUnit Style Database Unit Testing ACCU London – 20 th January 2011 Chris Oldwood

Slides:



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

Using xUnit as a Swiss-Army Testing Toolkit (Does Unit Size Matter?) ACCU Conference 2011 Chris Oldwood
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Batches, Scripts, Transactions-SQL Server 7. A batch is a set of Transact-SQL statements that are interpreted together by SQL Server. They are submitted.
1 Constraints, Triggers and Active Databases Chapter 9.
Transact-SQL. 1. Declare float = 10 select * from customers where discnt
CSE 544 Constraints Lecture #3 Friday, January 13, 2011 Dan Suciu , Winter
Advantage Data Dictionary. agenda Creating and Managing Data Dictionaries –Tables, Indexes, Fields, and Triggers –Defining Referential Integrity –Defining.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
#sqlsatPordenone #sqlsat367 February 28, 2015 Testing your databases Alessandro
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
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.
Transforming Data Models into Database Designs
Database Development Using TDD Chris Oldwood ACCU Conference /
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Chapter 7 Constraints and Triggers Spring 2011 Instructor: Hassan Khosravi.
SQL Constraints & Triggers May 10 th, Agenda Big picture –what are constraints & triggers? –where do they appear? –why are they important? In SQL.
Overview What is SQL Server? Creating databases Administration Security Backup.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
UNIT TESTING FOR SQL Prepared for SUGSA CodeLabs Alain King Paul Johnson.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
SQL Server 7.0 Maintaining Referential Integrity.
1 SQL Constraints and Programming. 2 Agenda Constraints in SQL Systems aspects of SQL.
ICS 321 Fall 2011 Constraints, Triggers, Views & Indexes Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
Constraints, Triggers and Views COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Data Driven Designs 99% of enterprise applications operate on database data or at least interface databases. Most common DBMS are Microsoft SQL Server,
1 SQL Constraints and Programming. 2 Agenda Constraints in SQL Systems aspects of SQL.
1 COP 4710 Databases Fall, 2000 Today’s Topic Chapter 7: SQL David A. Gaitros October 9th, 2000 Department of Computer Science.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Oracle 11g: SQL Chapter 4 Constraints.
Module 4: Implementing Data Integrity
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
How Microsoft Great Plains eEnterprise Utilizes SQL Server William Boynes Jr.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
DATABASE DEVELOPMENT WITH VSTS DATABASE EDITION By Chris Dahlberg ©2009 Aspect Software, Inc. All rights reserved. 1.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Slide 1 Chapter 7 – Part 3 Stored Procedure, Function &Trigger.
Test-Driven SQL Chris Oldwood Agile on the Beach /
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Constraints Review. What is a constraint? Unique – forbids duplicate values Referencial – Foreign key Check Constraint – sets restrictions on data added.
1 Announcements Reading for next week: Chapters 6 and 7  Next-to-Last reading from the text for a little while (I promise) Your database accounts should.
DATABASE DEVELOPMENT WITH VISUAL STUDIO 2010 Chris Dahlberg 1.
Ch 7. Working with relational data. Transactions Group of statements executed as a group. If all statements execute successfully, changes are committed.
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
Unit Testing with tSQLt
Copyright 2015 Varigence, Inc. Unit and Integration Testing in SSIS A New Approach Scott @varigence.
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
Get testing with tSQLt Practical examples and automation Steve Jones SQLServerCentral Red Gate Software.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Visual Studio Database Tools (aka SQL Server Data Tools)
Chapter 6 - Database Implementation and Use
Module 5: Implementing Data Integrity by Using Constraints
2018, Fall Pusan National University Ki-Joune Li
The PROCESS of Queries John Deardurff
The PROCESS of Queries John Deardurff
Introduction to VSTS Database Professional
SQL – Constraints & Triggers
Triggers 7/11/2019 See scm-intranet.
Presentation transcript:

xUnit Style Database Unit Testing ACCU London – 20 th January 2011 Chris Oldwood

Presentation Outline Database Development Process The xUnit Testing Model Test First Development Continuous Integration/Toolchain Pub

Legacy Database Development Shared development environment Only integration/system/stress tests No automated testing Only real data not test data Referential Integrity – all or nothing No automated build & deployment

Ideal Development Process Isolation Scaffolding Automation

Example Testable Behaviours Default constraint Trigger to cascade a delete Refactoring to a surrogate key

NUnit Test Model [TestFixture] public class ThingTests { [Test] public void Thing_DoesStuff_WhenAskedTo() { var input =...; var expected =...; var result =...; Assert.That(result, Is.EqualTo(expected)); }

NUnit Test Runner Tests packaged into assemblies Uses reflection to locate tests In-memory to minimise residual effects Output to UI/console

SQL Test Model create procedure test.Thing_DoesStuff_WhenAskedTo as varchar(100) =... varchar(100) =... varchar(100) =... go

SQL Test Runner Tests packaged into scripts (batches) Uses system tables to locate tests Uses transactions to minimise residual effects Output to UI/console

SQL Asserts Value comparisons (string, datetime, …) Table/result set row count Table/result set contents Error handling (constraint violations)

Setup & Teardown Per-Fixture (static data) Per-Test (specific data) Use helper procedures

Default Constraint Test create procedure test.AddingTask_SetsSubmitTime as int datetime = 1 insert into Task = t.SubmitTime from Task t where t.TaskId exec go

Trigger Test create procedure DeletingUser_DeletesUserSettings as... = 1 insert into AppUser insert into AppUserSettings delete from AppUser where UserId = count(*) from AppUserSettings where UserId exec 0 go

Unique Key Test create procedure AddingDuplicateCustomer_RaisesError as... insert into Customer values(‘duplicate’,...) begin try insert into Customer values(‘duplicate’,...) end try begin catch = 1 end catch exec go

Automation Enables easy regression testing Enables Continuous Integration Performance can be variable

Test First Development Start with a requirement Write a failing test Write production code Test via the public interface

The Public Interface Stored procedures Views Tables?

Implementation Details Primary keys Foreign keys Indexes Triggers Check constraints Default constraints

Deployment Testing Build version N+1 then run unit tests Build version N then patch to N+1 then run unit tests ==

Buy or Build? Batch file, SQL scripts & SQLCMD TSQLUnit & PL/Unit Visual Studio SQL Server/Oracle Express

“The Oldwood Thing” Chris Oldwood