![Page 1: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/1.jpg)
Offline Database Development
and Unit Testing with SSDT
Andrey Zavadskiy
![Page 2: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/2.jpg)
22
Thank YouPresenting Sponsors
Supporting Sponsors
Gain insights through familiar
tools while balancing monitoring
and managing user created
content across structured and
unstructured sources.
Unifying computer, storage,
networking, and virtualization, Cisco
UCS is the optimal database and
business intelligence platform for SQL
Server.
Solutions from Dell help you
monitor, manage, protect and
improve your SQL Server
environment.
www.microsoft.com www.cisco.com www.software.dell.com
![Page 3: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/3.jpg)
Planning on attending PASS Summit 2015? Start saving
today!
• The world’s largest gathering of SQL Server & BI professionals
• Take your SQL Server skills to the next level by learning from the world’s SQL
Server experts, in over 190 technical sessions
• Over 5000 attendees, representing 2000 companies, from 52 countries,
ready to network & learn
Contact your Local or Virtual Chapter for an
additional $150 discount.$1795
until July 12th, 2015
![Page 4: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/4.jpg)
Andrey Zavadskiy
4
Solutions architect, SQL & .NET developer
20 years in IT industry
Worked with SQL Server since 7.0 back in 2001
Developed in Visual Basic, C#, ASP.NET, MVC,
JavaScript, SharePoint
MCSE, MCSD, MCT
https://www.facebook.com/andrey.k.zavadskiy
@AndreyZavadskiy
https://www.linkedin.com/in/zavadskiy
http://andreyzavadskiy.com
![Page 5: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/5.jpg)
5
Session Goal
Provide a practical overview of how to use SQL Server Data Tools to create,
test and deploy a database project
5
![Page 6: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/6.jpg)
6
Contents
Offline database development Creating a database project
Creating database objects and writing T-SQL code
Project properties
Deployment
Deployment scripts for inserting data
Database unit testing Objects to be tested
Unit test flow
Creating and running unit test
Debugging database objects in unit test
Custom unit test conditions
6
![Page 7: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/7.jpg)
7
Concept of SQL Server Data Tools
Focusing on the final version of code rather then on many ALTER iterations
The unique IDE for all database developer’s needs
Based on Visual Studio
Working with connected databases (like SQL Server Management Studio)
Project approach to code writing
Debugging and unit testing
Version control (via integration with Team Foundation Server)
7
![Page 8: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/8.jpg)
8
Offline Database Development
Creating a database project
Creating database objects
Import from existing database
Creating from scratch
Project properties
Project and database settings
Code analysis
8
![Page 9: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/9.jpg)
9
DEMO
Creating a database project
9
![Page 10: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/10.jpg)
10
Database Deployment
Deployment in the connected database Publishes the script (CREATE)
Compares against the target database
Creates a change script (ALTER)
Runs the change script on the target database
Deployment in the disconnected database Creates a DACPAC package
Distribute and publish DACPAC Compares DACPAC against the target database
Creates a change script
Runs the change script on the target database
Publishing profiles and settings
10
![Page 11: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/11.jpg)
11
DEMO
Publishing a database
11
![Page 12: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/12.jpg)
12
Deployment Scripts For Inserting Data
Creating scripts
Based on the existing data
From scratch
Various types of scripts
Pre-deployment
Post-deployment
12
![Page 13: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/13.jpg)
13
DEMO
Scripting data for deployment
13
![Page 14: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/14.jpg)
14
Database Unit Testing
Unit test
Is performed on a smallest piece of testable code
Isolated from the other pieces of code
Should be repeatable
Gives the answer to only one question
Usually created by developers
14
![Page 15: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/15.jpg)
15
What for?
Confidence in your code
Confirms that product requirements are working
Early error checking of code
Instant visual feedback on errors
Helps to check subsequent changes in code
Provides documentation for other developers
15
![Page 16: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/16.jpg)
16
Where are the bugs?
16
Invoked unit of code
Unit of code Test
Dependency
![Page 17: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/17.jpg)
17
What can be tested?
Meta-data
Table structure, field type and length
Existence of objects
Constraints
CHECK, DEFAULT, PRIMARY KEY, FOREIGN KEY, UNIQUE
T-SQL code
Stored procedures, Functions, Triggers
Security permissions
Execution time
17
![Page 18: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/18.jpg)
18
Data that can be tested
Scalar values
Normal values
Errors (incorrect values)
Very big values
NULL
Table values
Rowset
Empty rowset
Very big rowset
Metadata
18
![Page 19: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/19.jpg)
19
Unit Test Flow
Test initialize
Unit test
Pre-test
Test
Post-test
Test cleanup
Can have more than one test condition
Can handle exceptions raised in database
Can be run within a transaction
19
![Page 20: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/20.jpg)
20
DEMO
Creating and running a database unit tests
20
![Page 21: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/21.jpg)
21
Debugging in unit tests
Can debug only the T-SQL code to be tested
Breakpoint can be set inside the stored procedure, function or trigger
Can’t debug the T-SQL code of the unit test itself
21
![Page 22: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/22.jpg)
22
DEMO
Debugging a code from within a database unit test
22
![Page 23: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/23.jpg)
23
Custom unit test conditions
Are a Visual Studio IDE extensions
Created in a separate project as a class library
Compiled to a DLL
How-to in MSDN article “Custom Test Conditions for SQL Server Unit Tests”
https://msdn.microsoft.com/en-us/library/jj860449(v=vs.103).aspx
Example in my CodePlex project https://ssdtconditions.codeplex.com/
23
![Page 24: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/24.jpg)
24
DEMO
Using a custom test conditions
24
![Page 25: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/25.jpg)
25
References
MSDN: SQL Server Data Tools
https://msdn.microsoft.com/en-us/library/hh272686(v=vs.103).aspx
SSDT Team Blog
http://blogs.msdn.com/b/ssdt/
MSDN Forum
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=ssdt
25
![Page 26: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/26.jpg)
Questions?
![Page 27: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/27.jpg)
Thank You for AttendingFollow @pass24hop
Share your thoughts with hashtags
#pass24hop & #sqlpass
![Page 28: Offline Database Development and Unit Testing with SSDTandreyzavadskiy.com/wp-content/uploads/2015/06/... · Database unit testing Objects to be tested Unit test flow Creating and](https://reader034.vdocuments.site/reader034/viewer/2022050308/5f70aeda43e7c446837880bd/html5/thumbnails/28.jpg)
SQL Server Agent: The Life
Preserver for the Drowning
DBA
Lance Tidwell
Coming Up Next …