SlideShare a Scribd company logo
ADDING UNIT TESTS WITH TSQLT TO
THE DATABASE DEPLOYMENT PIPELINE
Eduardo Piairo
@EdPiairo
#techinporto
ABOUT ME
Adding unit tests with tSQLt to the database deployment pipeline
@EdPiairo, #techinporto
@EdPiairo
https://pt.linkedin.com/in/eduardopiairo
eduardopiairo@gmail.com
https://www.eduardopiairo.com
Eduardo Piairo
DevOps Coach @ Natixis | DevOps Porto Co-Founder |Friend of Redgate
TSQLT
Adding unit tests with tSQLt to the database deployment 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, #techinporto
TSQLT INSTALL
Adding unit tests with tSQLt to the database deployment pipeline
• tSQLt.class.sql
• CLR
• clr enabled
• clr strict security
• Should be installed in the development database
@EdPiairo, #techinporto
WHAT’S A TSQLT TEST?
Adding unit tests with tSQLt to the database deployment 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
@EdPiairo, #techinporto
WHAT’S A TSQLT TEST?
Adding unit tests with tSQLt to the database deployment pipeline
• Benefits
• Business requirements documentation
• Code refactoring
• Isolation - unrelated changes do not affect other parts of the system
• Help structure code into distinct components – keep it small
@EdPiairo, #techinporto
TSQLT CREATE
Adding unit tests with tSQLt to the database deployment pipeline
EXEC tSQLt.NewTestClass my_new_test_class’;
GO
CREATE PROCEDURE my_new_test_class.[test something important]
AS
BEGIN
-------Assemble
--This section is for code that sets up the environment
-------Act
-- Execute the code under test like a stored procedure, function or view
-- and capture the results in variables or tables.
-------Assert
-- Compare the expected and actual
END;
@EdPiairo, #techinporto
TSQLT RUN
Adding unit tests with tSQLt to the database deployment pipeline
• tSQLt.RunAll
• Execute all the tests
• tSQLt.Run '[your_test_class].[your_test]
• Execute a specific test
• tSQLt.Run '[your_test_class]'
• Execute a specific test class
@EdPiairo, #techinporto
WHAT CAN BE TESTED?
Adding unit tests with tSQLt to the database deployment pipeline
• Stored Procedures
• Functions
• Views
• Tables
• Tables constrains that are critical
@EdPiairo, #techinporto
TESTING (WHITOUT DATA)
Adding unit tests with tSQLt to the database deployment pipeline
• Unit tests is about testing code
• You do not need a database full of data, you need the opposite
• Makes creating unit tests easy
• Data setup
• Only the necessary data for making the test work is needed
• Mocking
• tSQLt.FakeTable
• tSQLt.FakeFunction
• tSQLt.SpyProcedure @EdPiairo, #techinporto
ISOLATING OBJECTS
Adding unit tests with tSQLt to the database deployment pipeline
• tSQLt.FakeTable
• Fakes the original table without constrains
• Isolate the table from constrains – I don’t need unnecessary data
• tSQL.FakeFunction
• Simply replaces the original function
• Allow to simplify the logic
• tSQLt.SpyProcedure
• Replace the original SP with a spy
• The spy will record the parameters that were passed to it @EdPiairo, #techinporto
ISOLATING OBJECTS
Adding unit tests with tSQLt to the database deployment pipeline
• ApplyConstraint
• RemoveObjectIfExists
• ApplyTrigger
• RemoveObject
@EdPiairo, #techinporto
ASSERTS
Adding unit tests with tSQLt to the database deployment pipeline
• tSQLt.AsserEquals
• tSQLr.AssertEqualsTable
• tSQLt.AssertEmptyTable
• tSQLt.AssertEqualsString
• tSQLt.AssertEqualsTableSchema
• tSQLt.AssertLike
• tSQLt.AssertNotEquals
• AssertObjectDoesNotExist
• AssertObjectExists
• AssertResultSetsHaveSameMetaData
• Fail
@EdPiairo, #techinporto
SQLTEST
Adding unit tests with tSQLt to the database deployment pipeline
• Redgate SQL Test
• Add-in for SSMS for creating and running unit tests
• Measure the code coverage of those tests
@EdPiairo, #techinporto
ADDING TSQLT TO THE DEPLOYMENT PIPEPLINE
Adding unit tests with tSQLt to the database deployment pipeline
Source
Control
Continuous
Integration
Continuous
Delivery
@EdPiairo, #techinporto
ADDING TSQLT TO THE DEPLOYMENT PIPEPLINE
Adding unit tests with tSQLt to the database deployment pipeline
Source
Control
Continuous
Integration
Continuous
Delivery
@EdPiairo, #techinporto
SOURCE CONTROL
Adding unit tests with tSQLt to the database deployment pipeline
• GitHub
• T-SQL migrations
• tSQLt tests
• Pester tests
• Building scripts
@EdPiairo, #techinporto
CONTINUOUS INTEGRATION
Adding unit tests with tSQLt to the database deployment pipeline
• AzOps (ex VSTS)
• TEST environment setup (Local Machine | Docker)
• Test and Report
• Build artefact
@EdPiairo, #techinporto
CONTINUOUS DELIVERY
Adding unit tests with tSQLt to the database deployment pipeline
• Octopus Deploy
• Local Machine
• Azure
@EdPiairo, #techinporto
REFERENCES & MATERIALS
Adding unit tests with tSQLt to the database deployment pipeline
• References
• https://tsqlt.org/user-guide/
• https://courses.agilesql.club/
• Source code available @ GitHub
• https://github.com/eduardopiairo/devopsporto-db
@EdPiairo, #techinporto
Q&A
Adding unit tests with tSQLt to the database deployment pipeline
@EdPiairo
https://pt.linkedin.com/in/eduardopiairo
eduardopiairo@gmail.com
https://www.eduardopiairo.com
@EdPiairo, #techinporto

More Related Content

What's hot

Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512
Masayuki Igawa
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina Language
Lynn Langit
 
Bug zillatestopiajenkins
Bug zillatestopiajenkinsBug zillatestopiajenkins
Bug zillatestopiajenkins
Samira Kumar Nanda
 
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Max Lai
 
Continuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyreContinuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyre
Spark Summit
 
Hands-On Testing: How to Integrate Tests in OPNFV
Hands-On Testing: How to Integrate Tests in OPNFVHands-On Testing: How to Integrate Tests in OPNFV
Hands-On Testing: How to Integrate Tests in OPNFV
OPNFV
 
Upstream Testing Collaboration
Upstream Testing Collaboration Upstream Testing Collaboration
Upstream Testing Collaboration
OPNFV
 
Automated Infrastructure Testing
Automated Infrastructure TestingAutomated Infrastructure Testing
Automated Infrastructure Testing
Ranjib Dey
 
Challenge in asia region connecting each testbed and poc of distributed nfv ...
Challenge in asia region  connecting each testbed and poc of distributed nfv ...Challenge in asia region  connecting each testbed and poc of distributed nfv ...
Challenge in asia region connecting each testbed and poc of distributed nfv ...
OPNFV
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for Automatization
Sergey Arkhipov
 
Nautilus
NautilusNautilus
Nautilus
INRIA-OAK
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
Brice Fernandes
 
Regain Control Thanks To Prometheus
Regain Control Thanks To PrometheusRegain Control Thanks To Prometheus
Regain Control Thanks To Prometheus
Etienne Coutaud
 
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
Accumulo Summit
 
Qtip benchmarking as a service for opnfv
Qtip  benchmarking as a service for opnfvQtip  benchmarking as a service for opnfv
Qtip benchmarking as a service for opnfv
OPNFV
 
Villegas first pacsec_2016
Villegas first pacsec_2016Villegas first pacsec_2016
Villegas first pacsec_2016
PacSecJP
 
Hands-on monitoring with Prometheus
Hands-on monitoring with PrometheusHands-on monitoring with Prometheus
Hands-on monitoring with Prometheus
Brice Fernandes
 
12 Factors Kubernetes
12 Factors Kubernetes12 Factors Kubernetes
12 Factors Kubernetes
Etienne Coutaud
 
The journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramThe journey of asyncio adoption in instagram
The journey of asyncio adoption in instagram
Jimmy Lai
 
Spring Testing, Fight for the Context
Spring Testing, Fight for the ContextSpring Testing, Fight for the Context
Spring Testing, Fight for the Context
GlobalLogic Ukraine
 

What's hot (20)

Tempest scenariotests 20140512
Tempest scenariotests 20140512Tempest scenariotests 20140512
Tempest scenariotests 20140512
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina Language
 
Bug zillatestopiajenkins
Bug zillatestopiajenkinsBug zillatestopiajenkins
Bug zillatestopiajenkins
 
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
 
Continuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyreContinuous Integration for Spark Apps by Sean McIntyre
Continuous Integration for Spark Apps by Sean McIntyre
 
Hands-On Testing: How to Integrate Tests in OPNFV
Hands-On Testing: How to Integrate Tests in OPNFVHands-On Testing: How to Integrate Tests in OPNFV
Hands-On Testing: How to Integrate Tests in OPNFV
 
Upstream Testing Collaboration
Upstream Testing Collaboration Upstream Testing Collaboration
Upstream Testing Collaboration
 
Automated Infrastructure Testing
Automated Infrastructure TestingAutomated Infrastructure Testing
Automated Infrastructure Testing
 
Challenge in asia region connecting each testbed and poc of distributed nfv ...
Challenge in asia region  connecting each testbed and poc of distributed nfv ...Challenge in asia region  connecting each testbed and poc of distributed nfv ...
Challenge in asia region connecting each testbed and poc of distributed nfv ...
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for Automatization
 
Nautilus
NautilusNautilus
Nautilus
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
 
Regain Control Thanks To Prometheus
Regain Control Thanks To PrometheusRegain Control Thanks To Prometheus
Regain Control Thanks To Prometheus
 
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
Accumulo Summit 2015: Tracing in Accumulo and HDFS [Internals]
 
Qtip benchmarking as a service for opnfv
Qtip  benchmarking as a service for opnfvQtip  benchmarking as a service for opnfv
Qtip benchmarking as a service for opnfv
 
Villegas first pacsec_2016
Villegas first pacsec_2016Villegas first pacsec_2016
Villegas first pacsec_2016
 
Hands-on monitoring with Prometheus
Hands-on monitoring with PrometheusHands-on monitoring with Prometheus
Hands-on monitoring with Prometheus
 
12 Factors Kubernetes
12 Factors Kubernetes12 Factors Kubernetes
12 Factors Kubernetes
 
The journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramThe journey of asyncio adoption in instagram
The journey of asyncio adoption in instagram
 
Spring Testing, Fight for the Context
Spring Testing, Fight for the ContextSpring Testing, Fight for the Context
Spring Testing, Fight for the Context
 

Similar to Adding unit tests to the database deployment pipeline

Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
David P. Moore
 
Agile db testing_techniques
Agile db testing_techniquesAgile db testing_techniques
Agile db testing_techniques
Tarik Essawi
 
A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
Terry Bunio
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLt
Sergio Govoni
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
Red Gate Software
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
Ortus Solutions, Corp
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
QUONTRASOLUTIONS
 
QuerySurge for DevOps
QuerySurge for DevOpsQuerySurge for DevOps
QuerySurge for DevOps
RTTS
 
PaaSTA: Running applications at Yelp
PaaSTA: Running applications at YelpPaaSTA: Running applications at Yelp
PaaSTA: Running applications at Yelp
Nathan Handler
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
Jen Wong
 
How to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstackHow to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstack
Sławomir Kapłoński
 
Declarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data modelsDeclarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data models
Monal Daxini
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
Virtual JBoss User Group
 
Techorama 2017 - Testing the unit, and beyond.
Techorama 2017 - Testing the unit, and beyond.Techorama 2017 - Testing the unit, and beyond.
Techorama 2017 - Testing the unit, and beyond.
Bert Brouns
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
Dimitry Polivaev
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
Payara
 

Similar to Adding unit tests to the database deployment pipeline (20)

Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Agile db testing_techniques
Agile db testing_techniquesAgile db testing_techniques
Agile db testing_techniques
 
A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLt
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
 
QuerySurge for DevOps
QuerySurge for DevOpsQuerySurge for DevOps
QuerySurge for DevOps
 
PaaSTA: Running applications at Yelp
PaaSTA: Running applications at YelpPaaSTA: Running applications at Yelp
PaaSTA: Running applications at Yelp
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
How to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstackHow to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstack
 
Declarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data modelsDeclarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data models
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Techorama 2017 - Testing the unit, and beyond.
Techorama 2017 - Testing the unit, and beyond.Techorama 2017 - Testing the unit, and beyond.
Techorama 2017 - Testing the unit, and beyond.
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
 

More from Eduardo Piairo

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

More from Eduardo Piairo (20)

ADDO 2021: Why and how to include database changes in the deployment pipeline
ADDO 2021: Why and how to include database changes in the deployment pipelineADDO 2021: Why and how to include database changes in the deployment pipeline
ADDO 2021: Why and how to include database changes in the deployment pipeline
 
Start by changing the way of work
Start by changing the way of workStart by changing the way of work
Start by changing the way of work
 
Operations for databases – The DevOps journey
Operations for databases – The DevOps journey Operations for databases – The DevOps journey
Operations for databases – The DevOps journey
 
Deployment pipeline for databases
Deployment pipeline for databasesDeployment pipeline for databases
Deployment pipeline for databases
 
Deployment pipeline for databases
Deployment pipeline for databasesDeployment pipeline for databases
Deployment pipeline for databases
 
Operations for databases: the agile/devops journey
Operations for databases: the agile/devops journeyOperations for databases: the agile/devops journey
Operations for databases: the agile/devops journey
 
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
Setting a WordPress website using Azure Web Apps And Azure Database for MySQLSetting a WordPress website using Azure Web Apps And Azure Database for MySQL
Setting a WordPress website using Azure Web Apps And Azure Database for MySQL
 
SQL Server 2017 CLR
SQL Server 2017 CLRSQL Server 2017 CLR
SQL Server 2017 CLR
 
SQL Server 2017 CLR
SQL Server 2017 CLRSQL Server 2017 CLR
SQL Server 2017 CLR
 
Deployment pipeline for Azure SQL Databases
Deployment pipeline for Azure SQL DatabasesDeployment pipeline for Azure SQL Databases
Deployment pipeline for Azure SQL Databases
 
Operations for databases – the agile/devops journey
Operations for databases – the agile/devops journeyOperations for databases – the agile/devops journey
Operations for databases – the agile/devops journey
 
Delivering changes for applications and databases @ Azure
Delivering changes for applications and databases @ AzureDelivering changes for applications and databases @ Azure
Delivering changes for applications and databases @ Azure
 
Delivering changes for databases and applications
Delivering changes for databases and applicationsDelivering changes for databases and applications
Delivering changes for databases and applications
 
Workshop: Delivering chnages for applications and databases
Workshop: Delivering chnages for applications and databasesWorkshop: Delivering chnages for applications and databases
Workshop: Delivering chnages for applications and databases
 
Database Source Control: Migrations vs State
Database Source Control: Migrations vs StateDatabase Source Control: Migrations vs State
Database Source Control: Migrations vs State
 
Road to database automation: database source control
Road to database automation: database source controlRoad to database automation: database source control
Road to database automation: database source control
 
Deployment Pipeline for databases (Azure SQL Database, SQL Server)
Deployment Pipeline for databases (Azure SQL Database, SQL Server)Deployment Pipeline for databases (Azure SQL Database, SQL Server)
Deployment Pipeline for databases (Azure SQL Database, SQL Server)
 
Database Source Control: Migrations vs State
Database Source Control: Migrations vs StateDatabase Source Control: Migrations vs State
Database Source Control: Migrations vs State
 
Delivering changes for applications and databases
Delivering changes for applications and databasesDelivering changes for applications and databases
Delivering changes for applications and databases
 
DbOps, DevOps and Ops
DbOps, DevOps and OpsDbOps, DevOps and Ops
DbOps, DevOps and Ops
 

Recently uploaded

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

Adding unit tests to the database deployment pipeline

  • 1. ADDING UNIT TESTS WITH TSQLT TO THE DATABASE DEPLOYMENT PIPELINE Eduardo Piairo @EdPiairo #techinporto
  • 2. ABOUT ME Adding unit tests with tSQLt to the database deployment pipeline @EdPiairo, #techinporto @EdPiairo https://pt.linkedin.com/in/eduardopiairo eduardopiairo@gmail.com https://www.eduardopiairo.com Eduardo Piairo DevOps Coach @ Natixis | DevOps Porto Co-Founder |Friend of Redgate
  • 3. TSQLT Adding unit tests with tSQLt to the database deployment 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, #techinporto
  • 4. TSQLT INSTALL Adding unit tests with tSQLt to the database deployment pipeline • tSQLt.class.sql • CLR • clr enabled • clr strict security • Should be installed in the development database @EdPiairo, #techinporto
  • 5. WHAT’S A TSQLT TEST? Adding unit tests with tSQLt to the database deployment 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 @EdPiairo, #techinporto
  • 6. WHAT’S A TSQLT TEST? Adding unit tests with tSQLt to the database deployment pipeline • Benefits • Business requirements documentation • Code refactoring • Isolation - unrelated changes do not affect other parts of the system • Help structure code into distinct components – keep it small @EdPiairo, #techinporto
  • 7. TSQLT CREATE Adding unit tests with tSQLt to the database deployment pipeline EXEC tSQLt.NewTestClass my_new_test_class’; GO CREATE PROCEDURE my_new_test_class.[test something important] AS BEGIN -------Assemble --This section is for code that sets up the environment -------Act -- Execute the code under test like a stored procedure, function or view -- and capture the results in variables or tables. -------Assert -- Compare the expected and actual END; @EdPiairo, #techinporto
  • 8. TSQLT RUN Adding unit tests with tSQLt to the database deployment pipeline • tSQLt.RunAll • Execute all the tests • tSQLt.Run '[your_test_class].[your_test] • Execute a specific test • tSQLt.Run '[your_test_class]' • Execute a specific test class @EdPiairo, #techinporto
  • 9. WHAT CAN BE TESTED? Adding unit tests with tSQLt to the database deployment pipeline • Stored Procedures • Functions • Views • Tables • Tables constrains that are critical @EdPiairo, #techinporto
  • 10. TESTING (WHITOUT DATA) Adding unit tests with tSQLt to the database deployment pipeline • Unit tests is about testing code • You do not need a database full of data, you need the opposite • Makes creating unit tests easy • Data setup • Only the necessary data for making the test work is needed • Mocking • tSQLt.FakeTable • tSQLt.FakeFunction • tSQLt.SpyProcedure @EdPiairo, #techinporto
  • 11. ISOLATING OBJECTS Adding unit tests with tSQLt to the database deployment pipeline • tSQLt.FakeTable • Fakes the original table without constrains • Isolate the table from constrains – I don’t need unnecessary data • tSQL.FakeFunction • Simply replaces the original function • Allow to simplify the logic • tSQLt.SpyProcedure • Replace the original SP with a spy • The spy will record the parameters that were passed to it @EdPiairo, #techinporto
  • 12. ISOLATING OBJECTS Adding unit tests with tSQLt to the database deployment pipeline • ApplyConstraint • RemoveObjectIfExists • ApplyTrigger • RemoveObject @EdPiairo, #techinporto
  • 13. ASSERTS Adding unit tests with tSQLt to the database deployment pipeline • tSQLt.AsserEquals • tSQLr.AssertEqualsTable • tSQLt.AssertEmptyTable • tSQLt.AssertEqualsString • tSQLt.AssertEqualsTableSchema • tSQLt.AssertLike • tSQLt.AssertNotEquals • AssertObjectDoesNotExist • AssertObjectExists • AssertResultSetsHaveSameMetaData • Fail @EdPiairo, #techinporto
  • 14. SQLTEST Adding unit tests with tSQLt to the database deployment pipeline • Redgate SQL Test • Add-in for SSMS for creating and running unit tests • Measure the code coverage of those tests @EdPiairo, #techinporto
  • 15. ADDING TSQLT TO THE DEPLOYMENT PIPEPLINE Adding unit tests with tSQLt to the database deployment pipeline Source Control Continuous Integration Continuous Delivery @EdPiairo, #techinporto
  • 16. ADDING TSQLT TO THE DEPLOYMENT PIPEPLINE Adding unit tests with tSQLt to the database deployment pipeline Source Control Continuous Integration Continuous Delivery @EdPiairo, #techinporto
  • 17. SOURCE CONTROL Adding unit tests with tSQLt to the database deployment pipeline • GitHub • T-SQL migrations • tSQLt tests • Pester tests • Building scripts @EdPiairo, #techinporto
  • 18. CONTINUOUS INTEGRATION Adding unit tests with tSQLt to the database deployment pipeline • AzOps (ex VSTS) • TEST environment setup (Local Machine | Docker) • Test and Report • Build artefact @EdPiairo, #techinporto
  • 19. CONTINUOUS DELIVERY Adding unit tests with tSQLt to the database deployment pipeline • Octopus Deploy • Local Machine • Azure @EdPiairo, #techinporto
  • 20. REFERENCES & MATERIALS Adding unit tests with tSQLt to the database deployment pipeline • References • https://tsqlt.org/user-guide/ • https://courses.agilesql.club/ • Source code available @ GitHub • https://github.com/eduardopiairo/devopsporto-db @EdPiairo, #techinporto
  • 21. Q&A Adding unit tests with tSQLt to the database deployment pipeline @EdPiairo https://pt.linkedin.com/in/eduardopiairo eduardopiairo@gmail.com https://www.eduardopiairo.com @EdPiairo, #techinporto