SlideShare a Scribd company logo
Platinum
Sponsors



Gold
Sponsors




Silver
Sponsors
DATABASE UNIT TESTING
MADE EASY WITH VISUAL
STUDIO
Sanil Mhatre
Database Developer, Scottrade
About Me

   Database Developer –Scottrade (@scottradejobs)

   MCTS – MS SQL Server 2008 Database
    Development

   http://SQLWithSanil.com

   @SQLSuperGuru

   MSDN Forums & SQLServerCentral.com

   SQL Saturday #154 | St.Louis | Sept 15
Pre-requisites

   MS Visual Studio Team system framework & tools

   MS Visual Studio Team System (VSTS) 2010 &
    2012
       Ultimate & Premium Editions – create, modify & run
        database unit tests

       Professional Edition – run database unit tests but
        cannot create or modify them

   MS Visual Studio Team System 2008 Database
Agenda

   Software Testing – Basics
   Unit Testing – Basics
   Database Unit Testing – Principles,
    Terminology & Levels
   Demo – Implement Database Unit Testing with
    VSTS 2010 & MS SQL Server 2008 R2
   New features in VSTS 2012
Software Testing
   Meet Requirements & Expectations
   Deterministic & Predictable outcome
Types of Software Testing
Criteria               Black Box Testing        White Box Testing
                       Method in which the
                                                Method in which the
                       internal design/
                                                internal design/
                       implementation of the
Definition                                      implementation of the
                       item being tested is
                                                item being tested is
                       NOT known to the
                                                known to the tester.
                       tester
                       Mainly applicable to
                                                Mainly applicable to
                       higher levels of
                                                lower levels of
Levels Applicable To   testing:Acceptance
                                                testing:Unit Testing
                       Testing
                                                Integration Testing
                       System Testing
                       Generally, independent   Generally, Software
Responsibility
                       Software Testers         Developers
Programming
                       Not Required             Required
Knowledge
Levels of Software Testing

   Unit Testing

   Integration Testing

   System Testing

   System Integration Testing
What is Unit Testing ?
   Validation & Verification Methodology
   Belongs to the White Box testing category
   Test individual units of Source Code
   Unit – smallest testable part of application
       Method, Function, Class

   Tests created before or during development
   Tests conducted during development
Goals of Database Unit Testing

   Ensure quality & accuracy of database
    deliverables

   Establish a baseline state of your database

   Verify Subsequent changes made to database
    objects

   Identify regression issues throughout the
    application lifecycle
Database Unit Testing
Terminology
           • Isolated Environment (database)
           • Local development, testing &
SandBox      validation
           • Created by Script, VSTS Project
             or Restoring backup



           • Exercises a targeted code path
TestCase   • Multiple assertions
Database Unit Testing
Terminology

            • Simple Condition to
              indicate success or failure
            • Returns a True or False
            • Verifies Expected
Assertion     Interface
            • Verifies extraneous
              Results
            • Verifies data modification
              behavior
Database Unit Testing
Terminology

         • Collection of all test cases
 Unit      for a given stored procedure
         • Tests interface, code &
 Test      behavior

         • TSQL Scripts that executes a
           test case
 Test    • May include assertions like;
           • Return values
Script     • Output parameters
           • Expected Errors
Database Unit Testing
Terminology

         • Logical & named grouping
           of related unit tests
         • Multiple test lists can be
 Test      created
         • Can be run as a unit
 List    • A test suite
         • Builds & Check in Policy
         • Deprecated in VSTS 2012
Database Unit Testing
Terminology

          • TSQL Scripts
          • Prepare database for unit
Setup       testing
   &      • Returns database back to pre
            test state after testing
Cleanu    • Framework also provides
   p        common Initialize & Cleanup
            Scripts
Scripts   • Pre Test and Post Test Scripts
          • Data Generation Plans
Database Unit Testing
  Principles
Isolation
• Outcome of one test must not affect the outcome of
  any other test(s)
• Each test must return the database back to its
  previous state after execution
Independence
• One test case must not depend on any other test case
• Each test case must be run independently of any other
  test case
• Test case assertion must be independent of the order
  of it’s execution
Database Unit Testing
    Principles
Characteristics of Ideal Unit Test
• Exercise all possible code paths
• Evaluate all possible conditions
• Validate correct behavior for each path/condition

Considerable efforts for exhaustive testing
•   Non Trivial stored procedures
•   Number of input parameters
•   Permutations of optional parameters
•   Error code paths
Testable Interfaces of a Stored
Procedure

     Input &     • Name
     Output      • Data Type (Length)
   Parameters    • Optionality


   Return Code • Success/failure



    Row Count    • SET NOCOUNT ON/OFF
Testable Interfaces of a Stored
Procedure
                  •   One or more SELECT statements
                  •   Number of Columns
   Result Set     •   Column Ordinal position
                  •   Column Name & Data Type


  Informational • PRINT Messages
    Messages    • RaiseError – Severity 10 & below



     Error        • RaiseError – Severity 10 & above
   Messages
Unit Test Conditions
Predefined Test conditions in VSTS 2010
   Data Checksum
   Empty ResultSet/Non Empty Result Set
   Execution Time
   Expected Schema
   Row Count
   Scalar Value
   Inconclusive
Levels of Unit Testing
Factors Affecting the choice of Appropriate Level
of Unit testing

        Costs of Unit test development & maintenance


         Added Value of Quality


         Application Criticality & Frequency of use

         Project Deadlines
Levels of Unit Testing


          • Smallest amount of testing
          • Ensures error free compiles
          • No code is exercised
          • Consists of single test case
Minimal     with SET FMTONLY ON
          • Executes with NULL inputs
          • Intrinsic Assertion – No
            Errors
Levels of Unit Testing

          • Exercises commonly used
            code paths & conditions
          • One step above Minimal
          • Tests Empty/Non-Empty
Margina     Result sets
   l      • Some assertion of typical
            behavior & expected
            interface
          • Not a thorough & complete
            test
Levels of Unit Testing

          • Exercises all code paths &
            conditions
          • Test cases for all permutations of
            optional parameters
Complet   • Multiple Assertions to completely
            verify interface & behavior
  e       • Could also verify column names
            of result set
          • It’s an exhaustive unit test to
            verify all but unexpected errors
Levels of Unit Testing

   Possible to develop and un-testable stored
    procedure ?
       A search stored procedure with 8 optional parameters
        will need over 2000 test cases

       Numerous found/not found conditions

       Error validation

   Possibly an indicator of flawed design

   Consider refactoring to facilitate testability
Demo

   Prerequisite : Database Project Exists in VSTS

   Create a Unit Test Project in VSTS

   Configure SandBox

   Create Tests

   Run Tests
New in VSTS 2012

   Redesigned Unit Test Explorer
   Support for 3rd party testing frameworks
   Code Analysis improvements
   Continuous test runner
   Deprecated Features
     Test   lists
     Generate       Unit Test Wizards
Conclusion

   Software Testing - Basics

   Unit Testing – Basics

   Database Unit Testing – Detailed discussion on
    Principles, Goals & Levels

   Demo – Implementation of Database Unit
    Testing with VSTS 2010 & SQL Server 2008 R2
Resources

   MSDN
     http://msdn.microsoft.com/en-

     us/library/aa833283.aspx

     http://msdn.microsoft.com/en-

     us/library/aa833423.aspx

   Wikipedia
     http://en.wikipedia.org/wiki/Software_testing


   Image - http://i.swebee.com/content/error-404-
THANK YOU !

Questions & Feedback

More Related Content

What's hot

Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
XavierDevroey
 
Unit testing
Unit testingUnit testing
Unit testing
Slideshare
 
Testing artifacts test cases
Testing artifacts   test casesTesting artifacts   test cases
Testing artifacts test cases
Petro Chernii
 
Unit testing on embedded target with C++Test
Unit testing on embedded  target with C++TestUnit testing on embedded  target with C++Test
Unit testing on embedded target with C++Test
Engineering Software Lab
 
Testing strategies
Testing strategiesTesting strategies
Testing strategies
chaitanya_yarlagadda
 
Integration in component based technology
Integration in component based technologyIntegration in component based technology
Integration in component based technology
Saransh Garg
 
Software Testing
Software TestingSoftware Testing
Software Testing
Kiran Kumar
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testing
Tao He
 
Unit testing
Unit testingUnit testing
Unit testing
princezzlove
 
Test case design
Test case designTest case design
Test case design
99pillar
 
Testing
TestingTesting
Testing
nazeer pasha
 
debugging and testing
debugging and testingdebugging and testing
debugging and testing
Sevajothi Crafts
 
Test execution may_04_2006
Test execution may_04_2006Test execution may_04_2006
Test execution may_04_2006
SivaprasanthRentala1975
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testing
Haris Jamil
 
White box & Black box testing
White box & Black box testingWhite box & Black box testing
White box & Black box testing
NitishMhaske1
 
Quality Analyst Training - Gain America
Quality Analyst Training - Gain AmericaQuality Analyst Training - Gain America
Quality Analyst Training - Gain America
GainAmerica
 
White box black box & gray box testing
White box black box & gray box testingWhite box black box & gray box testing
White box black box & gray box testing
Himanshu
 
Test Techniques
Test TechniquesTest Techniques
Test Techniques
nazeer pasha
 
Chapter 14 software testing techniques
Chapter 14 software testing techniquesChapter 14 software testing techniques
Chapter 14 software testing techniques
SHREEHARI WADAWADAGI
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++
Matt Hargett
 

What's hot (20)

Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
Unit testing
Unit testingUnit testing
Unit testing
 
Testing artifacts test cases
Testing artifacts   test casesTesting artifacts   test cases
Testing artifacts test cases
 
Unit testing on embedded target with C++Test
Unit testing on embedded  target with C++TestUnit testing on embedded  target with C++Test
Unit testing on embedded target with C++Test
 
Testing strategies
Testing strategiesTesting strategies
Testing strategies
 
Integration in component based technology
Integration in component based technologyIntegration in component based technology
Integration in component based technology
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test case design
Test case designTest case design
Test case design
 
Testing
TestingTesting
Testing
 
debugging and testing
debugging and testingdebugging and testing
debugging and testing
 
Test execution may_04_2006
Test execution may_04_2006Test execution may_04_2006
Test execution may_04_2006
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testing
 
White box & Black box testing
White box & Black box testingWhite box & Black box testing
White box & Black box testing
 
Quality Analyst Training - Gain America
Quality Analyst Training - Gain AmericaQuality Analyst Training - Gain America
Quality Analyst Training - Gain America
 
White box black box & gray box testing
White box black box & gray box testingWhite box black box & gray box testing
White box black box & gray box testing
 
Test Techniques
Test TechniquesTest Techniques
Test Techniques
 
Chapter 14 software testing techniques
Chapter 14 software testing techniquesChapter 14 software testing techniques
Chapter 14 software testing techniques
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++
 

Viewers also liked

Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
Erkin Ünlü
 
How to improve your unit tests?
How to improve your unit tests?How to improve your unit tests?
How to improve your unit tests?
Péter Módos
 
Unit Testing SQL Server
Unit Testing SQL ServerUnit Testing SQL Server
Unit Testing SQL Server
Giovanni Scerra ☃
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
Hazem Saleh
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
Josh Mock
 
Project Quality Planning and KickOff
Project Quality Planning and KickOffProject Quality Planning and KickOff
Project Quality Planning and KickOff
kaushikanirudh
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Joe Tremblay
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
Knoldus Inc.
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
Aliaa Monier Ismaail
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 
Software Testing
Software TestingSoftware Testing
Software Testing
Mousmi Pawar
 

Viewers also liked (12)

Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
How to improve your unit tests?
How to improve your unit tests?How to improve your unit tests?
How to improve your unit tests?
 
Unit Testing SQL Server
Unit Testing SQL ServerUnit Testing SQL Server
Unit Testing SQL Server
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Project Quality Planning and KickOff
Project Quality Planning and KickOffProject Quality Planning and KickOff
Project Quality Planning and KickOff
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Software Testing
Software TestingSoftware Testing
Software Testing
 

Similar to Database Unit Testing Made Easy with VSTS

General Software Tester Training
General Software Tester TrainingGeneral Software Tester Training
General Software Tester Training
Chris Scofield
 
Software engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit designSoftware engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit design
Maitree Patel
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
Software testing
Software testingSoftware testing
Software testing
Preeti Mishra
 
Software testing-and-analysis
Software testing-and-analysisSoftware testing-and-analysis
Software testing-and-analysis
WBUTTUTORIALS
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
Jordi Pradel
 
Fundamentals of software part 1
Fundamentals of software part 1Fundamentals of software part 1
Fundamentals of software part 1
Siddharth Sharma
 
testing strategies and tactics
 testing strategies and tactics testing strategies and tactics
testing strategies and tactics
Preeti Mishra
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
Heritage Institute Of Tech,India
 
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test ScenarioFundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
Siddharth Sharma
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
Mohamed Taman
 
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
TEST Huddle
 
Manual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testingManual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testing
Vibrant Technologies & Computers
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
weili_at_slideshare
 
Testing strategies -2
Testing strategies -2Testing strategies -2
Testing strategies -2
Divya Tiwari
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
mianshafa
 
Software Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails ApplicationsSoftware Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails Applications
Bhavin Javia
 
Share point 2010 unit and integration testing
Share point 2010 unit and integration testingShare point 2010 unit and integration testing
Share point 2010 unit and integration testing
Eric Shupps
 
Softwar tetesting basic
Softwar tetesting basicSoftwar tetesting basic
Softwar tetesting basic
parekhjigarh
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
Jitendra Zaa
 

Similar to Database Unit Testing Made Easy with VSTS (20)

General Software Tester Training
General Software Tester TrainingGeneral Software Tester Training
General Software Tester Training
 
Software engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit designSoftware engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit design
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Software testing
Software testingSoftware testing
Software testing
 
Software testing-and-analysis
Software testing-and-analysisSoftware testing-and-analysis
Software testing-and-analysis
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
 
Fundamentals of software part 1
Fundamentals of software part 1Fundamentals of software part 1
Fundamentals of software part 1
 
testing strategies and tactics
 testing strategies and tactics testing strategies and tactics
testing strategies and tactics
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test ScenarioFundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
Fundamentals of software 2 | Test Case | Test Suite | Test Plan | Test Scenario
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
C.V, Narayanan - Open Source Tools for Test Management - EuroSTAR 2010
 
Manual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testingManual testing - Introduction to Manual Software testing
Manual testing - Introduction to Manual Software testing
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Testing strategies -2
Testing strategies -2Testing strategies -2
Testing strategies -2
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
Software Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails ApplicationsSoftware Quality and Test Strategies for Ruby and Rails Applications
Software Quality and Test Strategies for Ruby and Rails Applications
 
Share point 2010 unit and integration testing
Share point 2010 unit and integration testingShare point 2010 unit and integration testing
Share point 2010 unit and integration testing
 
Softwar tetesting basic
Softwar tetesting basicSoftwar tetesting basic
Softwar tetesting basic
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 

Recently uploaded

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
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
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.
 
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
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
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
 
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
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
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
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

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
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
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
 
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
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
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
 
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
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
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
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

Database Unit Testing Made Easy with VSTS

  • 2. DATABASE UNIT TESTING MADE EASY WITH VISUAL STUDIO Sanil Mhatre Database Developer, Scottrade
  • 3. About Me  Database Developer –Scottrade (@scottradejobs)  MCTS – MS SQL Server 2008 Database Development  http://SQLWithSanil.com  @SQLSuperGuru  MSDN Forums & SQLServerCentral.com  SQL Saturday #154 | St.Louis | Sept 15
  • 4. Pre-requisites  MS Visual Studio Team system framework & tools  MS Visual Studio Team System (VSTS) 2010 & 2012  Ultimate & Premium Editions – create, modify & run database unit tests  Professional Edition – run database unit tests but cannot create or modify them  MS Visual Studio Team System 2008 Database
  • 5. Agenda  Software Testing – Basics  Unit Testing – Basics  Database Unit Testing – Principles, Terminology & Levels  Demo – Implement Database Unit Testing with VSTS 2010 & MS SQL Server 2008 R2  New features in VSTS 2012
  • 6. Software Testing  Meet Requirements & Expectations  Deterministic & Predictable outcome
  • 7. Types of Software Testing Criteria Black Box Testing White Box Testing Method in which the Method in which the internal design/ internal design/ implementation of the Definition implementation of the item being tested is item being tested is NOT known to the known to the tester. tester Mainly applicable to Mainly applicable to higher levels of lower levels of Levels Applicable To testing:Acceptance testing:Unit Testing Testing Integration Testing System Testing Generally, independent Generally, Software Responsibility Software Testers Developers Programming Not Required Required Knowledge
  • 8. Levels of Software Testing  Unit Testing  Integration Testing  System Testing  System Integration Testing
  • 9. What is Unit Testing ?  Validation & Verification Methodology  Belongs to the White Box testing category  Test individual units of Source Code  Unit – smallest testable part of application  Method, Function, Class  Tests created before or during development  Tests conducted during development
  • 10. Goals of Database Unit Testing  Ensure quality & accuracy of database deliverables  Establish a baseline state of your database  Verify Subsequent changes made to database objects  Identify regression issues throughout the application lifecycle
  • 11. Database Unit Testing Terminology • Isolated Environment (database) • Local development, testing & SandBox validation • Created by Script, VSTS Project or Restoring backup • Exercises a targeted code path TestCase • Multiple assertions
  • 12. Database Unit Testing Terminology • Simple Condition to indicate success or failure • Returns a True or False • Verifies Expected Assertion Interface • Verifies extraneous Results • Verifies data modification behavior
  • 13. Database Unit Testing Terminology • Collection of all test cases Unit for a given stored procedure • Tests interface, code & Test behavior • TSQL Scripts that executes a test case Test • May include assertions like; • Return values Script • Output parameters • Expected Errors
  • 14. Database Unit Testing Terminology • Logical & named grouping of related unit tests • Multiple test lists can be Test created • Can be run as a unit List • A test suite • Builds & Check in Policy • Deprecated in VSTS 2012
  • 15. Database Unit Testing Terminology • TSQL Scripts • Prepare database for unit Setup testing & • Returns database back to pre test state after testing Cleanu • Framework also provides p common Initialize & Cleanup Scripts Scripts • Pre Test and Post Test Scripts • Data Generation Plans
  • 16. Database Unit Testing Principles Isolation • Outcome of one test must not affect the outcome of any other test(s) • Each test must return the database back to its previous state after execution Independence • One test case must not depend on any other test case • Each test case must be run independently of any other test case • Test case assertion must be independent of the order of it’s execution
  • 17. Database Unit Testing Principles Characteristics of Ideal Unit Test • Exercise all possible code paths • Evaluate all possible conditions • Validate correct behavior for each path/condition Considerable efforts for exhaustive testing • Non Trivial stored procedures • Number of input parameters • Permutations of optional parameters • Error code paths
  • 18. Testable Interfaces of a Stored Procedure Input & • Name Output • Data Type (Length) Parameters • Optionality Return Code • Success/failure Row Count • SET NOCOUNT ON/OFF
  • 19. Testable Interfaces of a Stored Procedure • One or more SELECT statements • Number of Columns Result Set • Column Ordinal position • Column Name & Data Type Informational • PRINT Messages Messages • RaiseError – Severity 10 & below Error • RaiseError – Severity 10 & above Messages
  • 20. Unit Test Conditions Predefined Test conditions in VSTS 2010  Data Checksum  Empty ResultSet/Non Empty Result Set  Execution Time  Expected Schema  Row Count  Scalar Value  Inconclusive
  • 21. Levels of Unit Testing Factors Affecting the choice of Appropriate Level of Unit testing Costs of Unit test development & maintenance Added Value of Quality Application Criticality & Frequency of use Project Deadlines
  • 22. Levels of Unit Testing • Smallest amount of testing • Ensures error free compiles • No code is exercised • Consists of single test case Minimal with SET FMTONLY ON • Executes with NULL inputs • Intrinsic Assertion – No Errors
  • 23. Levels of Unit Testing • Exercises commonly used code paths & conditions • One step above Minimal • Tests Empty/Non-Empty Margina Result sets l • Some assertion of typical behavior & expected interface • Not a thorough & complete test
  • 24. Levels of Unit Testing • Exercises all code paths & conditions • Test cases for all permutations of optional parameters Complet • Multiple Assertions to completely verify interface & behavior e • Could also verify column names of result set • It’s an exhaustive unit test to verify all but unexpected errors
  • 25. Levels of Unit Testing  Possible to develop and un-testable stored procedure ?  A search stored procedure with 8 optional parameters will need over 2000 test cases  Numerous found/not found conditions  Error validation  Possibly an indicator of flawed design  Consider refactoring to facilitate testability
  • 26. Demo  Prerequisite : Database Project Exists in VSTS  Create a Unit Test Project in VSTS  Configure SandBox  Create Tests  Run Tests
  • 27. New in VSTS 2012  Redesigned Unit Test Explorer  Support for 3rd party testing frameworks  Code Analysis improvements  Continuous test runner  Deprecated Features  Test lists  Generate Unit Test Wizards
  • 28. Conclusion  Software Testing - Basics  Unit Testing – Basics  Database Unit Testing – Detailed discussion on Principles, Goals & Levels  Demo – Implementation of Database Unit Testing with VSTS 2010 & SQL Server 2008 R2
  • 29. Resources  MSDN  http://msdn.microsoft.com/en- us/library/aa833283.aspx  http://msdn.microsoft.com/en- us/library/aa833423.aspx  Wikipedia  http://en.wikipedia.org/wiki/Software_testing  Image - http://i.swebee.com/content/error-404-
  • 30. THANK YOU ! Questions & Feedback

Editor's Notes

  1. http://msdn.microsoft.com/en-us/library/dd172118.aspxhttp://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14258
  2. http://msdn.microsoft.com/en-us/library/dd172118.aspxhttp://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14258
  3. Goals of Software Testing ;Assure the Quality of a Software DeliverableEnsure the software meets requirement specsEnsure the software meets user expectations as well as stakeholder expectationsEnsure that the behaviour of the system is predictable and deterministichttp://en.wikipedia.org/wiki/Software_testingImage - http://i.swebee.com/content/error-404-road.jpg
  4. White-box testing is when the tester has access to the internal data structures and algorithms including the code that implements these.Black-box testing treats the software as a "black box"—without any knowledge of internal implementation. The black-box tester has no "bonds" with the code, and a tester's perception is very simple: a code must have bugs. Using the principle, "Ask and you shall receive," black-box testers find bugs where programmers do not. On the other hand, black-box testing has been said to be "like a walk in a dark labyrinth without a flashlight," because the tester doesn't know how the software being tested was actually constructed. As a result, there are situations when (1) a tester writes many test cases to check something that could have been tested by only one test case, and/or (2) some parts of the back-end are not tested at all.Grey-box testinginvolves having knowledge of internal data structures and algorithms for purposes of designing tests, while executing those tests at the user, or black-box level. By knowing the underlying concepts of how the software works, the tester makes better-informed testing choices while testing the software from outside. Grey-box testing implements intelligent test scenarios, based on limited information. http://en.wikipedia.org/wiki/Software_testinghttp://softwaretestingfundamentals.com/differences-between-black-box-testing-and-white-box-testing/
  5. Unit testing - also known as component testing, refers to tests that verify the functionality of a specific section of code, usually at the function levelIntegration testing - Integration testing is any type of software testing that seeks to verify the interfaces between components against a software designSystem testing - tests a completely integrated system to verify that it meets its requirementsSystem integration testing -  verifies that a system is integrated to any external or third-party systems defined in the system requirements
  6. SandboxA database sandbox is a private environment used for local unit testing and development. The sandbox allows development and testing to be done in isolation from other development activity and ensures repeatable results. Database developers use sandboxes to perform unit testing and validate rollout script behavior. Application developers may use local database sandboxes to test application code without affecting, or being affected by, other development activity. A database sandbox may be created from script, by deploying a VSTSDE database project locally, or by restoring a database backup at a known state.Test CaseA test cast exercises a targeted code path. Success or failure is ascertained after test case execution by asserting that the expected outcome was realized. Multiple assertions are commonly needed to validate the desired outcome of a specific test case.
  7. AssertionAn assertion is a simple condition that returns "true" to indicate test success or "false" to indicate failure of a test case. A test case assertion verifies:expected interface output values (e.g. output parameter values, number of resultsets, number of rows, resultset values, etc.)no extraneous results (e.g. errors, extra resultsets, unexpected informational messages, etc.)data modification behavior (e.g. data correctly inserted/updated/deleted)
  8. Unit TestA unit test is the collection of all of the test cases that exercise a stored procedure interface and code along with the assertions need to verify correct behavior.Test ScriptA test script is a T-SQL script that executes a test case. A test script may also include assertions implemented in T-SQL, such as checking return code values, output parameter values or a TRY/CATCH to assert an expected RAISERROR of a user-defined error occurred.
  9. Multiple related unit tests may be grouped together in a test list within VSTSDE so all can be run as a unit and for logical organizational purposes (a.k.a. test suite). http://msdn.microsoft.com/en-us/library/ms182461.aspxhttp://msdn.microsoft.com/en-us/library/ms182463.aspx
  10. Setup and Cleanup ScriptsSetup and cleanup scripts (a.k.a. fixture and teardown scripts) are T-SQL scripts used to prepare the database for unit testing and return the database back to the initial state afterward. Setup scripts typically insert data needed by a test case while cleanup scripts remove testing artifacts after test case execution. The VSTSDE unit test framework provides common Test Initialize and Test Cleanup scripts that are run before/after each test case within a unit test. This allows the same scripts to be shared by all test cases within a unit test. VSTSDE also includes the ability to run Pre-Test and Post-Test scripts before/after an individual test case. Pre/Post scripts are especially appropriate for data tailored for a specific test case. VSTSDE Data Generation Plans provide an alternative to unit test setup scripts. However, data values must be customized so that test cases can be developed against known data values. Care must be used to ensure DGP changes do not adversely affect existing unit tests and that cleanup scripts restore modified data back to the original state after test case execution.
  11. Unit Test explorer replaces the old test view and test results windowUsing simple plugin adapters, third party test frameworks can plug into the test platform layer and get the full experience of running inside of Visual Studio