SlideShare a Scribd company logo
ADDING UNIT TESTS WITH TSQLT TO THE
DATABASE DEPLOYMENT PIPELINE
Eduardo Piairo
@EdPiairo
#PortoData
ABOUT ME
Adding unit tests with tSQLt to the database pipeline
@EdPiairo, #PortoData
@EdPiairo
https://pt.linkedin.com/in/jesuspiairo
eduardopiairo@gmail.com
http://www.eduardopiairo.com/
Eduardo Piairo
Operations Engineer
DevOps Porto Founder
TSQLT
Adding unit tests with tSQLt to the database pipeline
• Database unit testing framework for Microsoft SQL Server
• Allow to write T-SQL code as tests
• Tests are automatically run within transactions
• Provides a way to isolate code and tables using mocking
• Output can be plain text or XML
@EdPiairo, #PortoData
TSQLT INSTALL
Adding unit tests with tSQLt to the database pipeline
• tSQLt.class.sql
• CLR
• clr enabled
• clr strict security
• Should be installed in the development database
@EdPiairo, #PortoData
WHAT’S A TSQLT TEST?
Adding unit tests with tSQLt to the database pipeline
• Stored Procedure
• Starts with the word test
• Must be in a schema that contains the extended property tSQLt.TestClass = 1
• tSQLt.NewTestClass
• Each test is wrapped in a transaction: modifications are rolled back and the results saved
• Benefits
• Requirements documentation
• Ability to refactor
• Isolation - unrelated changes do not affect other parts of the system
• Help structure code into distinct components
@EdPiairo, #PortoData
WHAT’S CAN BE TESTED?
Adding unit tests with tSQLt to the database pipeline
• Stored Procedures
• Functions
• Views
• Tables
• Tables constrains that are critical
@EdPiairo, #PortoData
TESTING WHITOUT DATA
Adding unit tests with tSQLt to the database pipeline
• Unit tests is about testing code
• You do not need a database full of data, you need the opposite
• Data setup
• Only the necessary data for making the test work is needed
• Mocking
• tSQLt.FakeTable
• tSQLt.FakeFunction
• tSQLt.SpyProcedure
@EdPiairo, #PortoData
ASSERTS
Adding unit tests with tSQLt to the database pipeline
• tSQLt.AsserEquals
• tSQLr.AssertEqualsTable
• tSQLt.AssertEmptyTable
• tSQLt.AssertEqualsString
• tSQLt.AssertEqualsTableS
chema
• tSQLt.AssertLike
• tSQLt.AssertNotEquals
• AssertObjectDoesNotExist
• AssertObjectExists
• AssertResultSetsHaveSam
eMetaData
• Fail
@EdPiairo, #PortoData
DEMO
Adding unit tests with tSQLt to the database pipeline
@EdPiairo, #PortoData
REFERENCES
Adding unit tests with tSQLt to the database pipeline
• http://tsqlt.org/user-guide/tSQLr.AssertEqualsTable
• https://courses.agilesql.club/
@EdPiairo, #PortoData
Q&A
Operations for databases
@EdPiairo
https://pt.linkedin.com/in/jesuspiairo
eduardopiairo@gmail.com
http://www.eduardopiairo.com/
@EdPiairo, #PortoData

More Related Content

What's hot (12)

PPT
Aptira presents OpenStack swift architecture and monitoring
OpenStack
 
PDF
Coscup 2013 : Continuous Integration on top of hadoop
Wisely chen
 
PDF
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
NETWAYS
 
PPTX
Soap UI - Lesson3
Qualitest
 
PDF
Parser Breakout Session
Zhipeng Huang
 
PDF
Bettercap
Shritesh Bhattarai
 
PPSX
Contributing code to cassandra
odpeer
 
PPTX
Spring Testing, Fight for the Context
GlobalLogic Ukraine
 
PPTX
Log Search Service Introduction
Alex Tregubov
 
PPTX
Reproducibility with Checkpoint & RRO
Work-Bench
 
PPTX
The ultimate container monitoring bake-off - Rancher Online Meetup October 2016
Shannon Williams
 
PPTX
PyCon TW 2018 - A Python Engineer Under Giant Umbrella (巨大保護傘下的 Python 碼農辛酸史)
Kir Chou
 
Aptira presents OpenStack swift architecture and monitoring
OpenStack
 
Coscup 2013 : Continuous Integration on top of hadoop
Wisely chen
 
OSMC 2021 | Robotmk: You don’t run IT – you deliver services!
NETWAYS
 
Soap UI - Lesson3
Qualitest
 
Parser Breakout Session
Zhipeng Huang
 
Contributing code to cassandra
odpeer
 
Spring Testing, Fight for the Context
GlobalLogic Ukraine
 
Log Search Service Introduction
Alex Tregubov
 
Reproducibility with Checkpoint & RRO
Work-Bench
 
The ultimate container monitoring bake-off - Rancher Online Meetup October 2016
Shannon Williams
 
PyCon TW 2018 - A Python Engineer Under Giant Umbrella (巨大保護傘下的 Python 碼農辛酸史)
Kir Chou
 

Similar to Adding unit tests with tSQLt to the database deployment pipeline (13)

PDF
Database development unit test with tSQLt
Sergio Govoni
 
PDF
A data driven etl test framework sqlsat madison
Terry Bunio
 
PDF
Unit Testing SQL Server
Giovanni Scerra ☃
 
PPTX
Get Testing with tSQLt - SQL In The City Workshop 2014
Red Gate Software
 
PDF
Test Driven Development with Sql Server
David P. Moore
 
PDF
SELJE_Database_Unit_Testing_Slides.pdf
Eric Selje
 
PPTX
tSQLt Database Unit Testing
Dexter Baga
 
PPT
A testing framework for Microsoft SQL-Server
elliando dias
 
PDF
SQLDay 2017 - Database Unit Tests with tSQLt
Marek Maśko
 
PPTX
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Alessandro Alpi
 
PDF
Agile db testing_techniques
Tarik Essawi
 
PDF
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
Jacek Gebal
 
PPT
Automated Testing with Databases
elliando dias
 
Database development unit test with tSQLt
Sergio Govoni
 
A data driven etl test framework sqlsat madison
Terry Bunio
 
Unit Testing SQL Server
Giovanni Scerra ☃
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Red Gate Software
 
Test Driven Development with Sql Server
David P. Moore
 
SELJE_Database_Unit_Testing_Slides.pdf
Eric Selje
 
tSQLt Database Unit Testing
Dexter Baga
 
A testing framework for Microsoft SQL-Server
elliando dias
 
SQLDay 2017 - Database Unit Tests with tSQLt
Marek Maśko
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Alessandro Alpi
 
Agile db testing_techniques
Tarik Essawi
 
POUG Meetup 1st MArch 2019 - utPLSQL v3 - Testing Framework for PL/SQL
Jacek Gebal
 
Automated Testing with Databases
elliando dias
 
Ad

More from Eduardo Piairo (20)

PDF
ADDO 2021: Why and how to include database changes in the deployment pipeline
Eduardo Piairo
 
PDF
Start by changing the way of work
Eduardo Piairo
 
PDF
Operations for databases – The DevOps journey
Eduardo Piairo
 
PDF
Deployment pipeline for databases
Eduardo Piairo
 
PDF
Deployment pipeline for databases
Eduardo Piairo
 
PDF
Operations for databases: the agile/devops journey
Eduardo Piairo
 
PDF
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
Eduardo Piairo
 
PDF
SQL Server 2017 CLR
Eduardo Piairo
 
PDF
SQL Server 2017 CLR
Eduardo Piairo
 
PDF
Deployment pipeline for Azure SQL Databases
Eduardo Piairo
 
PDF
Operations for databases – the agile/devops journey
Eduardo Piairo
 
PDF
Delivering changes for applications and databases @ Azure
Eduardo Piairo
 
PDF
Delivering changes for databases and applications
Eduardo Piairo
 
PDF
Workshop: Delivering chnages for applications and databases
Eduardo Piairo
 
PDF
Database Source Control: Migrations vs State
Eduardo Piairo
 
PDF
Road to database automation: database source control
Eduardo Piairo
 
PDF
Deployment Pipeline for databases (Azure SQL Database, SQL Server)
Eduardo Piairo
 
PPTX
Database Source Control: Migrations vs State
Eduardo Piairo
 
PDF
Delivering changes for applications and databases
Eduardo Piairo
 
PDF
DbOps, DevOps and Ops
Eduardo Piairo
 
ADDO 2021: Why and how to include database changes in the deployment pipeline
Eduardo Piairo
 
Start by changing the way of work
Eduardo Piairo
 
Operations for databases – The DevOps journey
Eduardo Piairo
 
Deployment pipeline for databases
Eduardo Piairo
 
Deployment pipeline for databases
Eduardo Piairo
 
Operations for databases: the agile/devops journey
Eduardo Piairo
 
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
Eduardo Piairo
 
SQL Server 2017 CLR
Eduardo Piairo
 
SQL Server 2017 CLR
Eduardo Piairo
 
Deployment pipeline for Azure SQL Databases
Eduardo Piairo
 
Operations for databases – the agile/devops journey
Eduardo Piairo
 
Delivering changes for applications and databases @ Azure
Eduardo Piairo
 
Delivering changes for databases and applications
Eduardo Piairo
 
Workshop: Delivering chnages for applications and databases
Eduardo Piairo
 
Database Source Control: Migrations vs State
Eduardo Piairo
 
Road to database automation: database source control
Eduardo Piairo
 
Deployment Pipeline for databases (Azure SQL Database, SQL Server)
Eduardo Piairo
 
Database Source Control: Migrations vs State
Eduardo Piairo
 
Delivering changes for applications and databases
Eduardo Piairo
 
DbOps, DevOps and Ops
Eduardo Piairo
 
Ad

Recently uploaded (20)

PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Import Data Form Excel to Tally Services
Tally xperts
 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 

Adding unit tests with tSQLt to the database deployment pipeline

  • 1. ADDING UNIT TESTS WITH TSQLT TO THE DATABASE DEPLOYMENT PIPELINE Eduardo Piairo @EdPiairo #PortoData
  • 2. ABOUT ME Adding unit tests with tSQLt to the database pipeline @EdPiairo, #PortoData @EdPiairo https://pt.linkedin.com/in/jesuspiairo [email protected] http://www.eduardopiairo.com/ Eduardo Piairo Operations Engineer DevOps Porto Founder
  • 3. TSQLT Adding unit tests with tSQLt to the database pipeline • Database unit testing framework for Microsoft SQL Server • Allow to write T-SQL code as tests • Tests are automatically run within transactions • Provides a way to isolate code and tables using mocking • Output can be plain text or XML @EdPiairo, #PortoData
  • 4. TSQLT INSTALL Adding unit tests with tSQLt to the database pipeline • tSQLt.class.sql • CLR • clr enabled • clr strict security • Should be installed in the development database @EdPiairo, #PortoData
  • 5. WHAT’S A TSQLT TEST? Adding unit tests with tSQLt to the database pipeline • Stored Procedure • Starts with the word test • Must be in a schema that contains the extended property tSQLt.TestClass = 1 • tSQLt.NewTestClass • Each test is wrapped in a transaction: modifications are rolled back and the results saved • Benefits • Requirements documentation • Ability to refactor • Isolation - unrelated changes do not affect other parts of the system • Help structure code into distinct components @EdPiairo, #PortoData
  • 6. WHAT’S CAN BE TESTED? Adding unit tests with tSQLt to the database pipeline • Stored Procedures • Functions • Views • Tables • Tables constrains that are critical @EdPiairo, #PortoData
  • 7. TESTING WHITOUT DATA Adding unit tests with tSQLt to the database pipeline • Unit tests is about testing code • You do not need a database full of data, you need the opposite • Data setup • Only the necessary data for making the test work is needed • Mocking • tSQLt.FakeTable • tSQLt.FakeFunction • tSQLt.SpyProcedure @EdPiairo, #PortoData
  • 8. ASSERTS Adding unit tests with tSQLt to the database pipeline • tSQLt.AsserEquals • tSQLr.AssertEqualsTable • tSQLt.AssertEmptyTable • tSQLt.AssertEqualsString • tSQLt.AssertEqualsTableS chema • tSQLt.AssertLike • tSQLt.AssertNotEquals • AssertObjectDoesNotExist • AssertObjectExists • AssertResultSetsHaveSam eMetaData • Fail @EdPiairo, #PortoData
  • 9. DEMO Adding unit tests with tSQLt to the database pipeline @EdPiairo, #PortoData
  • 10. REFERENCES Adding unit tests with tSQLt to the database pipeline • http://tsqlt.org/user-guide/tSQLr.AssertEqualsTable • https://courses.agilesql.club/ @EdPiairo, #PortoData