SlideShare a Scribd company logo
Database Unit Tests with tSQLt
SQLDay 2017
About the Author
Marek Maśko
• Principal Database Analyst at Sabre
• Working with SQL Server for ~7 years
• SQL DBA, Dev & Architect
• MCP since 2012
• Contact Information:
Email: marek.masko@gmail.com
LinkedIn: https://pl.linkedin.com/in/marekmasko
Twitter: @MarekMasko
SQLDay 2017
Unit Tests
• Take the smallest testable piece of
software and test it in isolated conditions.
• F.I.R.S.T Principles:
– Fast
– Isolated
– Repeatable
– Self-Validating
– Thorough and Timely
SQLDay 2017
tSQLt Framework
• Open Source Framework
• Written in TSQL and C# (CLR)
• Runs on database level
• Provides various Assert methods
• Allows object mocking
http://tsqlt.org/
https://github.com/tSQLt-org/tSQLt
SQLDay 2017
What we get?
SQLDay 2017
Requirements
• Requires CLR (SQL Server 2005 SP2 +)
• tSQLt schema
• Trustworthy database
SQLDay 2017
Test creation and execution
• tSQLt.NewTestClass
• tSQLt.Run [ [@testName = ] 'test name' ]
• tSQLt.RunAll
SQLDay 2017
tSQLt.Run
tSQLt.Run
’test class’
For each [test*] SP
Create record in
tSQLt.TestResult
Start TRANRun Setup SPRun test SP
ROLLBACK
Update record in
tSQLt.TestResult
Print results
SQLDay 2017
Assertions
• tSQLt.AssertEmptyTable
• tSQLt.AssertEquals
• tSQLt.AssertEqualsString
• tSQLt.AssertEqualsTable
• tSQLt.AssertEqualsTableSchema
• tSQLt.AssertLike
• tSQLt.AssertNotEquals
• tSQLt.AssertObjectDoesNotExist
• tSQLt.AssertObjectExists
• tSQLt.AssertResultSetsHaveSameMetaData
• tSQLt.Fail
SQLDay 2017
Isolating Dependencies
Tables:
• tSQLt.FakeTable
• tSQLt.ApplyConstraint
• tSQLt.ApplyTrigger
Procedures:
• tSQLt.SpyProcedure
Functions:
• tSQLt.FakeFunction
SQLDay 2017
Something went wrong?
[tSQLt].[Private_RenamedObjectLog] for the rescue!
SELECT OriginalName,
SCHEMA_NAME(schema_id) +'.'+ name AS [Name of Renamed Table],
create_date
FROM [tSQLt].[Private_RenamedObjectLog]
JOIN sys.objects
ON objectid = object_id
SQLDay 2017
What else?
• SqlCop by George Mastros
– http://sqlcop.lessthandot.com
– http://dl.dropbox.com/u/58229865/SQLCop%20Tests.zip
• SQLCover Code Coverage by Ed Elliott
– https://the.agilesql.club/Projects/SQLCover
– https://github.com/GoEddie/SQLCover
– https://github.com/danielpalme/ReportGenerator
SQLDay 2017
Problems
• INSERT INTO … EXEC
• Synonyms
• Schema binding
• Watch out for time
• Exceptions from rules
• Cannot run tests in parallel
SQLDay 2017
Best practices
• Separate test class for each tested object
• Single assertion per test
• Parameters testing
• Resultset schema testing
• Table schema testing (prevent changes)
THANK YOU
AND GOOD LUCK!
SQLDay 2017 - Database Unit Tests with tSQLt

More Related Content

What's hot

Keep Calm And Serilog Elasticsearch Kibana on .NET Core
Keep Calm And Serilog Elasticsearch Kibana on .NET CoreKeep Calm And Serilog Elasticsearch Kibana on .NET Core
Keep Calm And Serilog Elasticsearch Kibana on .NET Core
Maciej Szymczyk
 
Refactoring Rails applications with RubyMine
Refactoring Rails applications with RubyMineRefactoring Rails applications with RubyMine
Refactoring Rails applications with RubyMine
Andrzej Krzywda
 
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
Maciej Szymczyk
 
Elk meetup boston - logz.io
Elk meetup boston -  logz.ioElk meetup boston -  logz.io
Elk meetup boston - logz.io
tomerlevy9
 
Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)
Oren Eini
 
The Holy Grail of continuous delivery in distributed teams environment
The Holy Grail of continuous delivery in distributed teams environmentThe Holy Grail of continuous delivery in distributed teams environment
The Holy Grail of continuous delivery in distributed teams environment
Szymon Kurcab
 
Testing course content converted
Testing course content convertedTesting course content converted
Testing course content converted
ShreemInstituteProfe
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Infra for startup
Infra for startupInfra for startup
Infra for startup
Sira Sujjinanont
 
Entity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlEntity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sql
Andrea Tosato
 
From Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, LvivFrom Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, Lviv
Andrzej Krzywda
 
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB
 
Async streams
Async streamsAsync streams
Async streams
Christian Nagel
 
Wongnai Engineering Story
Wongnai Engineering StoryWongnai Engineering Story
Wongnai Engineering Story
Pattrawoot Suesatayasilp
 
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
 Node.js server side render in the Age of APIs - Full Stack Toronto 2017 Node.js server side render in the Age of APIs - Full Stack Toronto 2017
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
Ruy Adorno
 
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
MongoDB
 
Node.js Dublin Meetup April 2014
Node.js Dublin Meetup April 2014Node.js Dublin Meetup April 2014
Node.js Dublin Meetup April 2014
Damian Beresford
 
TabTale Architecture Overview
TabTale Architecture OverviewTabTale Architecture Overview
TabTale Architecture Overview
Assaf Gannon
 
Sustainable software development / Jätkusuutlik tarkvaraarendus
Sustainable software development / Jätkusuutlik tarkvaraarendusSustainable software development / Jätkusuutlik tarkvaraarendus
Sustainable software development / Jätkusuutlik tarkvaraarendus
GreteStrandberg
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data Landscape
Ike Ellis
 

What's hot (20)

Keep Calm And Serilog Elasticsearch Kibana on .NET Core
Keep Calm And Serilog Elasticsearch Kibana on .NET CoreKeep Calm And Serilog Elasticsearch Kibana on .NET Core
Keep Calm And Serilog Elasticsearch Kibana on .NET Core
 
Refactoring Rails applications with RubyMine
Refactoring Rails applications with RubyMineRefactoring Rails applications with RubyMine
Refactoring Rails applications with RubyMine
 
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
Keep Calm And Serilog Elasticsearch Kibana on .NET Core - 132. Spotkanie WG.N...
 
Elk meetup boston - logz.io
Elk meetup boston -  logz.ioElk meetup boston -  logz.io
Elk meetup boston - logz.io
 
Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)Know thy cost (or where performance problems lurk)
Know thy cost (or where performance problems lurk)
 
The Holy Grail of continuous delivery in distributed teams environment
The Holy Grail of continuous delivery in distributed teams environmentThe Holy Grail of continuous delivery in distributed teams environment
The Holy Grail of continuous delivery in distributed teams environment
 
Testing course content converted
Testing course content convertedTesting course content converted
Testing course content converted
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
 
Infra for startup
Infra for startupInfra for startup
Infra for startup
 
Entity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlEntity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sql
 
From Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, LvivFrom Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, Lviv
 
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
 
Async streams
Async streamsAsync streams
Async streams
 
Wongnai Engineering Story
Wongnai Engineering StoryWongnai Engineering Story
Wongnai Engineering Story
 
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
 Node.js server side render in the Age of APIs - Full Stack Toronto 2017 Node.js server side render in the Age of APIs - Full Stack Toronto 2017
Node.js server side render in the Age of APIs - Full Stack Toronto 2017
 
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
MongoDB World 2018: Using Puppet, Ansible and Ops Manager to Create Your Own ...
 
Node.js Dublin Meetup April 2014
Node.js Dublin Meetup April 2014Node.js Dublin Meetup April 2014
Node.js Dublin Meetup April 2014
 
TabTale Architecture Overview
TabTale Architecture OverviewTabTale Architecture Overview
TabTale Architecture Overview
 
Sustainable software development / Jätkusuutlik tarkvaraarendus
Sustainable software development / Jätkusuutlik tarkvaraarendusSustainable software development / Jätkusuutlik tarkvaraarendus
Sustainable software development / Jätkusuutlik tarkvaraarendus
 
Survey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data LandscapeSurvey of the Microsoft Azure Data Landscape
Survey of the Microsoft Azure Data Landscape
 

Similar to SQLDay 2017 - Database Unit Tests with tSQLt

iForum 2015: SQL vs. NoSQL
iForum 2015: SQL vs. NoSQLiForum 2015: SQL vs. NoSQL
iForum 2015: SQL vs. NoSQL
Денис Резник
 
SQL vs. NoSQL. It's always a hard choice.
SQL vs. NoSQL. It's always a hard choice.SQL vs. NoSQL. It's always a hard choice.
SQL vs. NoSQL. It's always a hard choice.
Denis Reznik
 
The databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practicesThe databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practices
Kamil Nowinski
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8
Derek Jacoby
 
NoSQL for SQL Server Developers using Couchbase
NoSQL for SQL Server Developers using CouchbaseNoSQL for SQL Server Developers using Couchbase
NoSQL for SQL Server Developers using Couchbase
Brant Burnett
 
Moving advanced analytics to your sql server databases
Moving advanced analytics to your sql server databasesMoving advanced analytics to your sql server databases
Moving advanced analytics to your sql server databases
Enrico van de Laar
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
Harry Zheng
 
MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community engine
mathraq
 
Mongo DB at Community Engine
Mongo DB at Community EngineMongo DB at Community Engine
Mongo DB at Community Engine
Community Engine
 
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Microsoft TechNet - Belgium and Luxembourg
 
Untangling spring week10
Untangling spring week10Untangling spring week10
Untangling spring week10
Derek Jacoby
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
Serdar Buyuktemiz
 
SQL Server 2016 BI updates
SQL Server 2016 BI updatesSQL Server 2016 BI updates
SQL Server 2016 BI updates
Chris Testa-O'Neill
 
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
Marek Maśko
 
Oracle APEX Nitro
Oracle APEX NitroOracle APEX Nitro
Oracle APEX Nitro
Marko Gorički
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
Ahmed Farag
 
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg SchadData Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
Data Con LA
 
New features of sql server 2016 bi features
New features of sql server 2016 bi featuresNew features of sql server 2016 bi features
New features of sql server 2016 bi features
Chris Testa-O'Neill
 
New in Visual Studio and TFS 2013
New in Visual Studio and TFS 2013New in Visual Studio and TFS 2013
New in Visual Studio and TFS 2013
Tung Nguyen Thanh
 
Introduction to azure document db
Introduction to azure document dbIntroduction to azure document db
Introduction to azure document db
Antonios Chatzipavlis
 

Similar to SQLDay 2017 - Database Unit Tests with tSQLt (20)

iForum 2015: SQL vs. NoSQL
iForum 2015: SQL vs. NoSQLiForum 2015: SQL vs. NoSQL
iForum 2015: SQL vs. NoSQL
 
SQL vs. NoSQL. It's always a hard choice.
SQL vs. NoSQL. It's always a hard choice.SQL vs. NoSQL. It's always a hard choice.
SQL vs. NoSQL. It's always a hard choice.
 
The databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practicesThe databases in SSDT: A work with project and best practices
The databases in SSDT: A work with project and best practices
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8
 
NoSQL for SQL Server Developers using Couchbase
NoSQL for SQL Server Developers using CouchbaseNoSQL for SQL Server Developers using Couchbase
NoSQL for SQL Server Developers using Couchbase
 
Moving advanced analytics to your sql server databases
Moving advanced analytics to your sql server databasesMoving advanced analytics to your sql server databases
Moving advanced analytics to your sql server databases
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
 
MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community engine
 
Mongo DB at Community Engine
Mongo DB at Community EngineMongo DB at Community Engine
Mongo DB at Community Engine
 
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
 
Untangling spring week10
Untangling spring week10Untangling spring week10
Untangling spring week10
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
 
SQL Server 2016 BI updates
SQL Server 2016 BI updatesSQL Server 2016 BI updates
SQL Server 2016 BI updates
 
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
SQLSaturday 664 - Troubleshoot SQL Server performance problems like a Microso...
 
Oracle APEX Nitro
Oracle APEX NitroOracle APEX Nitro
Oracle APEX Nitro
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg SchadData Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
Data Con LA 2018 - Towards Data Science Engineering Principles by Joerg Schad
 
New features of sql server 2016 bi features
New features of sql server 2016 bi featuresNew features of sql server 2016 bi features
New features of sql server 2016 bi features
 
New in Visual Studio and TFS 2013
New in Visual Studio and TFS 2013New in Visual Studio and TFS 2013
New in Visual Studio and TFS 2013
 
Introduction to azure document db
Introduction to azure document dbIntroduction to azure document db
Introduction to azure document db
 

More from Marek Maśko

SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
Marek Maśko
 
SQL Operations Studio - new multi-platform tool for SQL Server database devel...
SQL Operations Studio - new multi-platform tool for SQL Server database devel...SQL Operations Studio - new multi-platform tool for SQL Server database devel...
SQL Operations Studio - new multi-platform tool for SQL Server database devel...
Marek Maśko
 
SQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML DataSQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML Data
Marek Maśko
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query Performance
Marek Maśko
 
DevOps and databases
DevOps and databasesDevOps and databases
DevOps and databases
Marek Maśko
 
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft EngineerPLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
Marek Maśko
 

More from Marek Maśko (6)

SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
 
SQL Operations Studio - new multi-platform tool for SQL Server database devel...
SQL Operations Studio - new multi-platform tool for SQL Server database devel...SQL Operations Studio - new multi-platform tool for SQL Server database devel...
SQL Operations Studio - new multi-platform tool for SQL Server database devel...
 
SQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML DataSQL Server - Querying and Managing XML Data
SQL Server - Querying and Managing XML Data
 
SQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query PerformanceSQL Server - Using Tools to Analyze Query Performance
SQL Server - Using Tools to Analyze Query Performance
 
DevOps and databases
DevOps and databasesDevOps and databases
DevOps and databases
 
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft EngineerPLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
 

Recently uploaded

Hyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
Hyderabad Call Girls 7339748667 With Free Home Delivery At Your DoorHyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
Hyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
Russian Escorts in Delhi 9711199171 with low rate Book online
 
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
PsychoTech Services
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
keesa2
 
Drownings spike from May to August in children
Drownings spike from May to August in childrenDrownings spike from May to August in children
Drownings spike from May to August in children
Bisnar Chase Personal Injury Attorneys
 
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your DoorAhmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
Russian Escorts in Delhi 9711199171 with low rate Book online
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
hiju9823
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
Timothy Spann
 
一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理
ugydym
 
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
PsychoTech Services
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENTHigh Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
ranjeet3341
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
Timothy Spann
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
osoyvvf
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
22ad0301
 
Do People Really Know Their Fertility Intentions? Correspondence between Sel...
Do People Really Know Their Fertility Intentions?  Correspondence between Sel...Do People Really Know Their Fertility Intentions?  Correspondence between Sel...
Do People Really Know Their Fertility Intentions? Correspondence between Sel...
Xiao Xu
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
uevausa
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
Vineet
 
Senior Engineering Sample EM DOE - Sheet1.pdf
Senior Engineering Sample EM DOE  - Sheet1.pdfSenior Engineering Sample EM DOE  - Sheet1.pdf
Senior Engineering Sample EM DOE - Sheet1.pdf
Vineet
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
newdirectionconsulta
 
CAP Excel Formulas & Functions July - Copy (4).pdf
CAP Excel Formulas & Functions July - Copy (4).pdfCAP Excel Formulas & Functions July - Copy (4).pdf
CAP Excel Formulas & Functions July - Copy (4).pdf
frp60658
 

Recently uploaded (20)

Hyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
Hyderabad Call Girls 7339748667 With Free Home Delivery At Your DoorHyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
Hyderabad Call Girls 7339748667 With Free Home Delivery At Your Door
 
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
Essential Skills for Family Assessment - Marital and Family Therapy and Couns...
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
 
Drownings spike from May to August in children
Drownings spike from May to August in childrenDrownings spike from May to August in children
Drownings spike from May to August in children
 
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your DoorAhmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
Ahmedabad Call Girls 7339748667 With Free Home Delivery At Your Door
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
 
一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理
 
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
Interview Methods - Marital and Family Therapy and Counselling - Psychology S...
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENTHigh Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
High Profile Call Girls Navi Mumbai ✅ 9833363713 FULL CASH PAYMENT
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
 
Do People Really Know Their Fertility Intentions? Correspondence between Sel...
Do People Really Know Their Fertility Intentions?  Correspondence between Sel...Do People Really Know Their Fertility Intentions?  Correspondence between Sel...
Do People Really Know Their Fertility Intentions? Correspondence between Sel...
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
 
Senior Engineering Sample EM DOE - Sheet1.pdf
Senior Engineering Sample EM DOE  - Sheet1.pdfSenior Engineering Sample EM DOE  - Sheet1.pdf
Senior Engineering Sample EM DOE - Sheet1.pdf
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
 
CAP Excel Formulas & Functions July - Copy (4).pdf
CAP Excel Formulas & Functions July - Copy (4).pdfCAP Excel Formulas & Functions July - Copy (4).pdf
CAP Excel Formulas & Functions July - Copy (4).pdf
 

SQLDay 2017 - Database Unit Tests with tSQLt

  • 1.
  • 2. Database Unit Tests with tSQLt
  • 3. SQLDay 2017 About the Author Marek Maśko • Principal Database Analyst at Sabre • Working with SQL Server for ~7 years • SQL DBA, Dev & Architect • MCP since 2012 • Contact Information: Email: marek.masko@gmail.com LinkedIn: https://pl.linkedin.com/in/marekmasko Twitter: @MarekMasko
  • 4. SQLDay 2017 Unit Tests • Take the smallest testable piece of software and test it in isolated conditions. • F.I.R.S.T Principles: – Fast – Isolated – Repeatable – Self-Validating – Thorough and Timely
  • 5. SQLDay 2017 tSQLt Framework • Open Source Framework • Written in TSQL and C# (CLR) • Runs on database level • Provides various Assert methods • Allows object mocking http://tsqlt.org/ https://github.com/tSQLt-org/tSQLt
  • 7. SQLDay 2017 Requirements • Requires CLR (SQL Server 2005 SP2 +) • tSQLt schema • Trustworthy database
  • 8. SQLDay 2017 Test creation and execution • tSQLt.NewTestClass • tSQLt.Run [ [@testName = ] 'test name' ] • tSQLt.RunAll
  • 9. SQLDay 2017 tSQLt.Run tSQLt.Run ’test class’ For each [test*] SP Create record in tSQLt.TestResult Start TRANRun Setup SPRun test SP ROLLBACK Update record in tSQLt.TestResult Print results
  • 10. SQLDay 2017 Assertions • tSQLt.AssertEmptyTable • tSQLt.AssertEquals • tSQLt.AssertEqualsString • tSQLt.AssertEqualsTable • tSQLt.AssertEqualsTableSchema • tSQLt.AssertLike • tSQLt.AssertNotEquals • tSQLt.AssertObjectDoesNotExist • tSQLt.AssertObjectExists • tSQLt.AssertResultSetsHaveSameMetaData • tSQLt.Fail
  • 11. SQLDay 2017 Isolating Dependencies Tables: • tSQLt.FakeTable • tSQLt.ApplyConstraint • tSQLt.ApplyTrigger Procedures: • tSQLt.SpyProcedure Functions: • tSQLt.FakeFunction
  • 12. SQLDay 2017 Something went wrong? [tSQLt].[Private_RenamedObjectLog] for the rescue! SELECT OriginalName, SCHEMA_NAME(schema_id) +'.'+ name AS [Name of Renamed Table], create_date FROM [tSQLt].[Private_RenamedObjectLog] JOIN sys.objects ON objectid = object_id
  • 13. SQLDay 2017 What else? • SqlCop by George Mastros – http://sqlcop.lessthandot.com – http://dl.dropbox.com/u/58229865/SQLCop%20Tests.zip • SQLCover Code Coverage by Ed Elliott – https://the.agilesql.club/Projects/SQLCover – https://github.com/GoEddie/SQLCover – https://github.com/danielpalme/ReportGenerator
  • 14. SQLDay 2017 Problems • INSERT INTO … EXEC • Synonyms • Schema binding • Watch out for time • Exceptions from rules • Cannot run tests in parallel
  • 15. SQLDay 2017 Best practices • Separate test class for each tested object • Single assertion per test • Parameters testing • Resultset schema testing • Table schema testing (prevent changes)