Introduction to unit and integration testing with tSQLt

Slides:



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

Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
#sqlsatPordenone #sqlsat367 February 28, 2015 Testing your databases Alessandro
DEV207. SSDT Database Services Database Services Analysis Services Reporting Services Integration Services.
Passage Three Introduction to Microsoft SQL Server 2000.
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.
Today’s Agenda Chapter 12 Admin Tasks Chapter 13 Automating Admin Tasks.
Introduction to SQL 2005 Security Nick Ward SQL Server Specialist Nick Ward SQL Server Specialist
1MIS 2008 / Merging Two Data Collections: Lessons Learned from the CCD-EDEN Merger EDEN Best-Practice Sharing Oregon File Preparation Practices.
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
UNIT TESTING FOR SQL Prepared for SUGSA CodeLabs Alain King Paul Johnson.
I Copyright © 2004, Oracle. All rights reserved. Introduction Copyright © 2004, Oracle. All rights reserved.
ISM 4212 Lab Creating DB Tables 02 copyright Lars Paul Linden 2007.
SQL Server User Group Meeting Reporting Services Tips & Tricks Presented by Jason Buck of Custom Business Solutions.
Performance Dash A free tool from Microsoft that provides some quick real time information about the status of your SQL Servers.
Database Change Management One solution to an often complex problem Kevin Hurwitz Headspring Systems
Understanding SQL Server 2008 Change Data Capture Bret Stateham Training Manager Vortex Learning Solutions blogs.netconnex.com.
DATABASE TOOLS CS 260 Database Systems. Overview  Database accounts  Oracle SQL Developer  MySQL Workbench.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Database projects in visual studio 2010 Anthony Brown
Database Projects in Visual Studio Improving Reliability & Productivity.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Real World SQL Server Data Tools Benjamin
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
Confidencial - TRACASA Automatize test [e- Reporting]
Visual Studio 2012: A Complete IDE (Debugging & Source Control) Kevin Howell.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Continuous Integration for Databases Steve Jones SQLServerCentral Red Gate Software.
Continuous Deployments using SSDT
Rong Lu Senior Program Manager Building Unity games in Visual Studio.
Getting to know U-SQL Azhagappan Arunachalam.  Sr Database Architect 
Unit Testing with tSQLt
Developing SQL/Server database in Visual Studio Introducing SQL /Server Data Tools Peter Lu.Net Practices Director Principle Architect Nexient March 19.
Blog: R YOU READY FOR.
MANAGEMENT DATA WAREHOUSE AND DATA COLLECTOR Ian Lanham.
DBMS Programs MS SQL Server & MySQL
SQL Compare & SQL Refactor
Visual Studio Database Tools (aka SQL Server Data Tools)
Making Your List and Checking It Twice
Introduction to Microsoft SQL Server 2016
Outsourcing Database Administration
Glasgow, SQL Server Meetup
Data Virtualization Demoette… Data Lineage Reporting
Delphi or C++ Builder, with Subversion and Jenkins
Data Virtualization Demoette… JDBC Clients
Database Unit Testing Fundamentals
DBA and IT Professional for ~9 years. Currently I am a Data Architect
Using FileTables Sam Nasr, MCSA, MCT, MVP NIS Technologies
Automated and Repeatable Test Cases for SQL Server Development
Deploying and Configuring SSIS Packages
Using FileTables Sam Nasr, MCAD, MCTS, MVP NIS Technologies
Mapping Shema and Recursively Managing Data
Testing Database Code with tSQLt
DevOps Database Administration
SQL Server Data Tools Gert Drapers
Continuous Integration For Databases
DevOps Database Administration
Prove to your boss your database is sound - Unit Testing with tSQLt
Intro to Unit Testing with tSQLt
Database Unit Testing Fundamentals
Visual Studio Database Tools (aka SQL Server Data Tools)
DBA for ~4+years, IT Professional for 7.5 years.
Outsourcing Database Administration
Your code is not just…your code
SSDT and Database Project Basics
Introduction to VSTS Database Professional
Dynamic Sql Not so scary?
Your code is not just…your code
Samir Behara, Senior Developer, EBSCO
Presentation transcript:

Introduction to unit and integration testing with tSQLt Elizabeth Noble elizabeth.a.noble@outlook.com @SQLZelda

Agenda Define database testing methods Setup tSQLt Create and run unit and integration tests

Purpose of Testing Unit testing - Test a single part of functionality Integration testing – Test interactions between more than one part of functionality

Advantages of Automated Testing Over time develop a collection of tests Confirm new or existing functionality did not break Find defects earlier in the development cycle

Downsides of Automated Testing Time consuming to create tests Can be difficult to design tests

How to Setup tSQLt Download tSQLt http://tsqlt.org/downloads/ 

How to Setup tSQLt CLR must be enabled Set database to TRUSTWORTHY EXEC sp_configure 'clr enabled', 1; RECONFIGURE; Set database to TRUSTWORTHY ALTER DATABASE < database name > SET TRUSTWORTHY ON;

How to Setup tSQLt Run tSQLt scripts Run the tSQLt.Class.sql http://tsqlt.org/user-guide/quick-start/#InstallToDevDb

How to Setup tSQLt Setup shortcut to run tSQLt Open SQL Server Management Studio Tools -> Options -> Keyboard -> Keyboard Shortcuts Shortcut: CTRL + 0 Stored procedure: EXECUTE <database name>.tSQLt.RunAll;

Set up tSQL NewTestClass – creates a schema to group unit tests test – begin stored procedure names NewTestClass – creates schema that lumps all units tests and related objects FakeTable – makes a copy of the table; if it is not used, IDENTITY column may be incremented SpyProcedure –not used to test current stored procedure, used to run a stored procedure in a stored procedure test stored procedure - Stored procedure must begin with "test" at the beginning to be run as a unit test

Creating tSQL unit tests FakeTable – allows tests to be run on a copy of the actual table SpyProcedure – runs a copy of a stored procedure AssertEqualsTable – compares table results of actual versus expected NewTestClass – creates schema that lumps all units tests and related objects FakeTable – makes a copy of the table; if it is not used, IDENTITY column may be incremented SpyProcedure –not used to test current stored procedure, used to run a stored procedure in a stored procedure test stored procedure - Stored procedure must begin with "test" at the beginning to be run as a unit test

Create and Run Tests Determine what should be tested Design test to fail Write SQL to get test to succeed Repeat as needed

Demo

Conclusion Use tests to confirm functionality Install tSQLt in a development environment Think small when developing unit tests Test interactions with integration tests Design units tests to fail to avoid false positives

Additional Topics tSQLt - http://tsqlt.org/user-guide/quick-start/#InstallToDevDb Other options SQL Test - http://www.red-gate.com/products/sql-development/sql-test/ MSDN - https://msdn.microsoft.com/en-us/library/aa833283(v=vs.100).aspx SQL Cop - http://sqlcop.lessthandot.com/ Related topics Source control

Questions