SlideShare une entreprise Scribd logo
1  sur  33
Unit testing in Visual Studio 2010

     Because it is a matter of quality!!!
Different Type of Tests
                 Automated tests aimed to verify the functionality of a little
                 piece of code, run very often by developers and from
                 automated build.
Unit Tests


                 Test Suites managed with Microsoft Test Manager, manually
                 executed from testers and associated with User Stories. Can
                 be automated with Action Recording
Manual Tests


                 Web Request record and replay to simulate the interaction
                 with web sites. Can be used to do load or stress test to
                 verify the behavior of software under heavy usage
Web Tests



                 Record and replay user interaction with UI, plugin-based
                 recorder to maximize reproducibility, generation of UiMap
                 that contains all the data used to reproduce the automation.
Coded UI Tests
Test and Lifecycle - Waterfall

        Requirements   Design    Develop      Test        Deploy



In waterfall processes testing has a well-defined phase, located between
Develop and Deploy. With such a process developers tend to do manual test
to verify that requirements are satisfied

Modern waterfall approaches tend to distribute testing in all the phases of
the process.
Test and Lifecycle - Waterfall
                              Requirement are software artifacts that can be tested
                              following basic principle of testing
                               The purpose of testing a program is to find problems
                                                       in it
                               The purpose of finding problem is to get them fixed
Requirements   Test              (Testing Computer Software – Cem Kaner et Al.)

      Requirements should be verified with stakeholders and users to
      verify that we are going to create the right software
      A mismatch between the program and its specification is an error
      in the program if and only if the specification exists and is correct
          A program that follows a terrible specification is terrible not
                                    perfect

                      (Testing Computer Software – Cem Kaner et Al.)
Test and Lifecycle - Waterfall
                        Even with Emerging Architecture you need to
                        validate the design of the software.
                        The design phase should produce a «proof of
                        concept» for each «typical» part of the software
                        Early testing on POC should be used to validate the
                        infrastructure
 Design    Test
                        Technique used: Unit Test, Performance Test


Testing of the Design phase should take place when:
 No existing architecture, start from scratch
 First project with new technology
 Strict performance requirements
 External service
 Verify testability of the architecture
Test and Lifecycle - Waterfall
                       During developement all form of testing are used
                       Unit test: used by developers to validate new code
                       Manual test: Used by test team to validate code for
                       «done» requirements
                       Coded UI test: Used by developers and test team to
                       automate testing through the interface
 Develop    Test




The main purpose of testing during development is guarantee quality of
the codebase.
When code is out of the developing phase, it should be ready to be
“beta tested” to find bug that are not caught during development.
Test and Lifecycle - Waterfall
                              Testing phase is where you find bug during real-
                              usage of the software
                              The software is usually in «beta» stage, meaning that
Real-usage    Formal bugfix
                              it can be used by real user.
                              This is the moment where you mainly use
                              Acceptance test with Microsoft Test Manager
 Develop
Quality


All defect found during this phase should be filled up in issue/bug tracker
to be investigated by the team
No developer should be allowed to «pick a bug» to fix it without a formal
review.
The aim of this phase is to fix all most important bugs of the software, as
well as gather user impression of the overall product, to make little
modification before the real shipping.
All steps should be reported.
Test and Lifecycle - Agile

         Requirements   Design    Develop     Test         Deploy



Each agile process has its own development cycle, but quite all of them
have an interactive cycle
Each interaction value is added to the software and this value should be
immediately available to Stakeholders
Acceptance and Unit Testing are the skeleton of this lifecycle, without
tests it is difficult to be really Agile. Testing permits to
      Establish Definition Of Done (Acceptance)
      Refactor and do incremental development (Unit testing)
      Clarify User Stories (Acceptance)
      Assure internal quality of the codebase (Unit testing in CI)
Unit Testing

xUnit test pattern and typical techniques
        of unit testing in VS2010
Unit test principle
          Automated: Test can be executed without user interaction


          Integrated: Written in the same language of the code to test, available
          in the same environment
Develop
          Standard: Many frameworks available

Develop
          Agile: Support for refactoring and agile lifecycle

Develop
          Pattern support: www.xunitpattern.org estabilish a ground language
          and series of pattern for unit testing in all language/environments
xUnit framework pattern
               Setup: Initial conditions are set to maximize
               reproducibility of the test
Setup

               Exercise: Code to be tested is executed, usually is a
               call to a single function or a series of calls.
Exercise


               Verify: An expectation is checked, if the expectation
               fails, the whole test is considered to be failed
Verify


               Teardown: If the test modify the system/environment
               everything is restored to a good / clean state
Teardown
Quality of good tests
          Automated: Test can be executed without user interaction


          Indipendent: The test does not depend on any other test


Develop
          Focused: The test should verify a single condition

Develop
          Repetable: Test depends only on precondition contained in the setup
          phase and it should give the same result at each execution
Develop
          Fast: Slow tests are not executed frequently
Test is First-Class code
                          Part of the project: testing code has the same
                          importance of tested code
Part of the project

                          Refactored: Time is spent refactoring and adapting
                          test code to the modifications of tested code.
Refactored


                          Time: writing good tests takes time  but having
                          good Unit Test suite dramatically raise quality 
Hard to write


                          Long run ROI: Sadly enough, Unit Testing usually
                          does not pay in the short time, so it is difficult to take
                          the path to unit testing
Plan for the future
DEMO

Basic of 4-phase test in Visual Studio
               2010
Test smells
                         Symptom: too much time to maintain tests
                         Impact: test are not executed and removed from suite
                         Cause: Code duplication, low quality test code
High maintenance

                         Symptom: test fails but the code under test is correct
                         Impact: time wasted to look for inexistent bugs
                         Cause: Test is too complex
Buggy tests


                         Symptom: test has conditional logic inside
                         Impact: it is not clear what it is testing
                         Cause: Dependence from environment, wrong logic
Conditional test logic

                         Symptom: it is difficult to understand what is tested
                         Impact: it is difficult to understand why it failed
                         Cause: Eager test, mystery guest, irrelevant
Obscure test             information, hard coded test data
Avoid test smells
          Users does not execute the test often


          Continuous integration automatically executes tests


Develop
          Test are slow, they needs several minutes to be executed

Develop
          Categorized test permits execution of only a little part of a test,
          continuous test tools (Mighty Moose, Test Impact) can automate this
Develop
          Manual intervention before test run

Develop
          Write unit test first, write test that is testable
Fixture

The most difficult part to create Unit
   Tests without smells is fixture
           management
The fixture
                         Everything is needed to create preconditions for the
                         execution of test, it can be data in database, setting
                         global variables, cleaning up file on disks, etc.
Setup       Exercise

                         This is the most complex part of the whole Unit-
                         Testing stuff, because it is the source of many smell

Verify      Teardown


Fresh Fixture – transient: The fixture is recreated at each test, at the end of
the test the system is restored to the original state
Fresh Fixture – persistent: Same as transient, but the system is not restored
at the end of the test
Shared Fixture: The fixture is shared for many test, it is created, then a series
of test is executed
Fresh transient
           Fixture is created during the setup phase, take track of every
Setup      modification that is done to the system.
           It is useful to create a mechanism that permits to schedule
           automatic cleanup at the end of the test.
Exercise



Verify


           Fixture is removed during the teardown phase, everything is
Teardown   restored.
           Garbage collector should not be used because it is not-
           deterministic.
           If multiple restore operations should be executed, use try-
           catch clause to be sure to cleanup the most of them
Fresh persistent
           Fixture is created during the setup phase, no need to track
Setup      operations

                          Next test will create another fixure, but every
Exercise   Setup          modification done by the previous test is still
                          there
                          This can augment the risk of interacting-test
Verify     Exercise
                          smell.
                          This technique is useful only if we are sure that
Teardown   Verify         the fresh persistent fixture will not impact
                          other tests.
                          It is useful mainly if the restore operation is
           Teardown
                          slow and you do not want to lose time.
Shared fixture
                 Fixture is created during the setup phase, modification are
Setup            tracked
                First test is executed, the test is composed only by Exercise
Exercise        and Verify steps
                                Subsequent tests execution will use the same
Verify          Exercise
                 Setup          fixture


                Verify          Exercise
                                 Setup



                                Verify         Exercise
                                                Setup

After the latest verification the fixture is
removed.        Teardown                       Verify




                                               Teardown
Shared fixture
Fixture Setup   Setup        Setup          Setup




                Exercise     Exercise       Exercise




                Verify       Verify         Verify




                Teardown     Teardown       Teardown       Teardown


A shared fixture is created before the execution of each test
Each test can create another specific fixture and remove it in
Setup/Teardown
After the latest test of the suite is executed the final Teardown is run to
remove the shared fixture.
Assertion

How to write good verification code
that maximize the advantage of unit
              testing
Assertion
          Single assertion: A test should verify only one fact of the code under
          test

          Clear assertion: Reading verification code should immediately clarify
          what fact we are testing
Develop
          Test named assertion: Name of the test should clarify the purpose
          and what is verified by the test.
Writing good assertions
          Too many assertions in the test


          Expected Object, create an object that reflect the status you want to
          check, name that object in clear way.
Develop
          Complex assertion code, that is not readable.

Develop
          Use FluentInterface based assertion frameworks (SharpTestEx)

Develop
          Magic values to verify return values or object properties

Develop
          Use good names for variables and expected values
Test doubles

 Creates fake component to be sure to
exercise only a single part of the system
Depend On Component
            The System Under Test dialogates with external
Setup       component and the verification phase has not access
            to it.
Exercise



Verify
                 SUT                  DOC


Teardown    If the test fails, we are not sure if the reason is in bug
            in the SUT or for a bug or different behavior of the
            DOC.
            It leads to erratic test and frequent debugging test
            smell.
Test Double

                  Setup
                                        Test Double


                  Exercise



                  Verify
                                        SUT


                  Teardown


We need to design the SUT to loose coupling with the DOC, with this
technique you can create a double of the DOC in the test.
The Test Double simulates the real component, but it has a well
defined and reproducible behavior that is defined in the Setup phase
Verifiable Test Double

                   Setup
                                          Test Double


                   Exercise



                   Verify
                                          SUT


                   Teardown


With a verifiable Test Double the Verify step can ask to Test Double to
verify how the SUT interacted with him during Exercise phase.
As an example, if you create a Test Double of an E-Mail sender
component, you can verify that during Exercise the SUT asked to
send an E-Mail.
Types of TestDoubles
                              Stub: its only purpose is to answer to the requests of
                              the SUT with well defined and known answers, or with
                              a default one
Stub

                              Dummy: It does nothing, simply avoid the SUT to
                              crash for missing components.
Dummy


                              Mock and Spy: Behave like a Stub, but also permits to
                              make assertion on how the SUT interacted with them.
Mock Object and Test Spy


                              Fake Object: It implements a DOC with minimal
                              functionality.
Fake Object
Database Testing

Testing a database is complex and
     needs specific techniques
Database Testing Basic
                       Sandbox: Each tester/environment should have a
                       dedicated database to execute testing. Minimize
                       dependency, maximize execution time avoid conflicts
Database Sandbox

                       Database Fixture: Shared fixture to minimize setup
                       time, use of Back Door Manipulation and
                       backup/restore attach/detach method. Heavy use of
Fixture Setup
                       Shared Fixture.
                       Smart teardown: Use preload at each test and make
                       every test transactional so you can rollback after each
                       verification phase
Teardown

                       Database Projects: Specific project type introduced
                       with VS2008 that contains a dedicated section to unit
                       testing.
Database Project
……

Contenu connexe

Tendances

Automation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadAutomation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadDurga Prasad
 
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...Anna Russo
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Test driven development
Test driven developmentTest driven development
Test driven developmentHarry Potter
 
Continuous delivery @åf consult
Continuous delivery @åf consultContinuous delivery @åf consult
Continuous delivery @åf consultTomas Riha
 
Continuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the RescueContinuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the RescueTechWell
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
Learning's from mobile testing
Learning's from mobile testingLearning's from mobile testing
Learning's from mobile testingVikrant Chauhan
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
Automation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadAutomation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadDurga Prasad
 
EclipseCon: Test Confessions - What Eclipsers think and do about testing
EclipseCon: Test Confessions - What Eclipsers think and do about testingEclipseCon: Test Confessions - What Eclipsers think and do about testing
EclipseCon: Test Confessions - What Eclipsers think and do about testingMichaela Greiler
 

Tendances (15)

Software Testing or Quality Assurance
Software Testing or Quality AssuranceSoftware Testing or Quality Assurance
Software Testing or Quality Assurance
 
Automation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadAutomation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabad
 
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
STAREAST 2011 - 7 Steps To Improving Software Quality using Microsoft Test Ma...
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Tdd dev session
Tdd dev sessionTdd dev session
Tdd dev session
 
Continuous delivery @åf consult
Continuous delivery @åf consultContinuous delivery @åf consult
Continuous delivery @åf consult
 
Continuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the RescueContinuous Automated Regression Testing to the Rescue
Continuous Automated Regression Testing to the Rescue
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Learning's from mobile testing
Learning's from mobile testingLearning's from mobile testing
Learning's from mobile testing
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Testing Best Practices
Testing Best PracticesTesting Best Practices
Testing Best Practices
 
Testing
TestingTesting
Testing
 
Automation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadAutomation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in Hyderabad
 
EclipseCon: Test Confessions - What Eclipsers think and do about testing
EclipseCon: Test Confessions - What Eclipsers think and do about testingEclipseCon: Test Confessions - What Eclipsers think and do about testing
EclipseCon: Test Confessions - What Eclipsers think and do about testing
 

Similaire à Unit Testing

Software Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By SrikanthSoftware Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By SrikanthSrikanth Krishnamoorthy
 
Manual testing
Manual testingManual testing
Manual testingVivek V
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing pptSavyasachi14
 
Unit testing
Unit testing Unit testing
Unit testing dubbu
 
03 test specification and execution
03   test specification and execution03   test specification and execution
03 test specification and executionClemens Reijnen
 
Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to managementweili_at_slideshare
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingCameron Presley
 
Infographic All Things You Should Know About Regression Testing
Infographic All Things You Should Know About Regression TestingInfographic All Things You Should Know About Regression Testing
Infographic All Things You Should Know About Regression TestingKiwiQA
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with AgileKen McCorkell
 
Software testing
Software testingSoftware testing
Software testingEng Ibrahem
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test CompleteVartika Saxena
 
11 steps of testing process - By Harshil Barot
11 steps of testing process - By Harshil Barot11 steps of testing process - By Harshil Barot
11 steps of testing process - By Harshil BarotHarshil Barot
 
Basic Guide to Manual Testing
Basic Guide to Manual TestingBasic Guide to Manual Testing
Basic Guide to Manual TestingHiral Gosani
 

Similaire à Unit Testing (20)

Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Software Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By SrikanthSoftware Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By Srikanth
 
Manual testing
Manual testingManual testing
Manual testing
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing
Unit testing Unit testing
Unit testing
 
Software testing
Software testing Software testing
Software testing
 
Manual testing
Manual testingManual testing
Manual testing
 
03 test specification and execution
03   test specification and execution03   test specification and execution
03 test specification and execution
 
Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to management
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Infographic All Things You Should Know About Regression Testing
Infographic All Things You Should Know About Regression TestingInfographic All Things You Should Know About Regression Testing
Infographic All Things You Should Know About Regression Testing
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
 
Software testing
Software testingSoftware testing
Software testing
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test Complete
 
Types of testing
Types of testingTypes of testing
Types of testing
 
11 steps of testing process - By Harshil Barot
11 steps of testing process - By Harshil Barot11 steps of testing process - By Harshil Barot
11 steps of testing process - By Harshil Barot
 
Basic Guide to Manual Testing
Basic Guide to Manual TestingBasic Guide to Manual Testing
Basic Guide to Manual Testing
 
Software testing
Software testingSoftware testing
Software testing
 

Plus de Gian Maria Ricci

Se non sviluppo codice non sto lavorando
Se non sviluppo codice non sto lavorandoSe non sviluppo codice non sto lavorando
Se non sviluppo codice non sto lavorandoGian Maria Ricci
 
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure Devops
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure DevopsGestire la qualità del codice con Visual Studio, SonarQube ed Azure Devops
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure DevopsGian Maria Ricci
 
Migrare da un VCS centralizzato a Git
Migrare da un VCS centralizzato a GitMigrare da un VCS centralizzato a Git
Migrare da un VCS centralizzato a GitGian Maria Ricci
 
Real World Build + Release automation in Azure DevOps
Real World Build + Release automation in Azure DevOpsReal World Build + Release automation in Azure DevOps
Real World Build + Release automation in Azure DevOpsGian Maria Ricci
 
Gestire i rilasci automatici con azure devops
Gestire i rilasci automatici con azure devopsGestire i rilasci automatici con azure devops
Gestire i rilasci automatici con azure devopsGian Maria Ricci
 
Build and release in code with azure devops pipelines
Build and release in code with azure devops pipelinesBuild and release in code with azure devops pipelines
Build and release in code with azure devops pipelinesGian Maria Ricci
 
Azure Pipeline in salsa yaml
Azure Pipeline in salsa yamlAzure Pipeline in salsa yaml
Azure Pipeline in salsa yamlGian Maria Ricci
 
Git gitflow pull requests in devops focused teams
Git gitflow pull requests in devops focused teamsGit gitflow pull requests in devops focused teams
Git gitflow pull requests in devops focused teamsGian Maria Ricci
 
Distribute your code with NUget and build vNext
Distribute your code with NUget and build vNextDistribute your code with NUget and build vNext
Distribute your code with NUget and build vNextGian Maria Ricci
 
Manage your environment with DSC
Manage your environment with DSCManage your environment with DSC
Manage your environment with DSCGian Maria Ricci
 
Introduction to Application insights
Introduction to Application insightsIntroduction to Application insights
Introduction to Application insightsGian Maria Ricci
 
Deploy applications with TFS Build
Deploy applications with TFS BuildDeploy applications with TFS Build
Deploy applications with TFS BuildGian Maria Ricci
 
TFS - Quale source control
TFS - Quale source controlTFS - Quale source control
TFS - Quale source controlGian Maria Ricci
 
Introduction to Visual Studio Online
Introduction to Visual Studio OnlineIntroduction to Visual Studio Online
Introduction to Visual Studio OnlineGian Maria Ricci
 
Come Organizzare il proprio Team Project
Come Organizzare il proprio Team ProjectCome Organizzare il proprio Team Project
Come Organizzare il proprio Team ProjectGian Maria Ricci
 

Plus de Gian Maria Ricci (20)

Se non sviluppo codice non sto lavorando
Se non sviluppo codice non sto lavorandoSe non sviluppo codice non sto lavorando
Se non sviluppo codice non sto lavorando
 
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure Devops
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure DevopsGestire la qualità del codice con Visual Studio, SonarQube ed Azure Devops
Gestire la qualità del codice con Visual Studio, SonarQube ed Azure Devops
 
Migrare da un VCS centralizzato a Git
Migrare da un VCS centralizzato a GitMigrare da un VCS centralizzato a Git
Migrare da un VCS centralizzato a Git
 
Real World Build + Release automation in Azure DevOps
Real World Build + Release automation in Azure DevOpsReal World Build + Release automation in Azure DevOps
Real World Build + Release automation in Azure DevOps
 
Gestire i rilasci automatici con azure devops
Gestire i rilasci automatici con azure devopsGestire i rilasci automatici con azure devops
Gestire i rilasci automatici con azure devops
 
Build and release in code with azure devops pipelines
Build and release in code with azure devops pipelinesBuild and release in code with azure devops pipelines
Build and release in code with azure devops pipelines
 
Azure Pipeline in salsa yaml
Azure Pipeline in salsa yamlAzure Pipeline in salsa yaml
Azure Pipeline in salsa yaml
 
Git gitflow pull requests in devops focused teams
Git gitflow pull requests in devops focused teamsGit gitflow pull requests in devops focused teams
Git gitflow pull requests in devops focused teams
 
Distribute your code with NUget and build vNext
Distribute your code with NUget and build vNextDistribute your code with NUget and build vNext
Distribute your code with NUget and build vNext
 
Manage your environment with DSC
Manage your environment with DSCManage your environment with DSC
Manage your environment with DSC
 
Introduction to Application insights
Introduction to Application insightsIntroduction to Application insights
Introduction to Application insights
 
Git branching model
Git branching modelGit branching model
Git branching model
 
Deploy applications with TFS Build
Deploy applications with TFS BuildDeploy applications with TFS Build
Deploy applications with TFS Build
 
TFS - Quale source control
TFS - Quale source controlTFS - Quale source control
TFS - Quale source control
 
Branch model in Git
Branch model in GitBranch model in Git
Branch model in Git
 
Introduction to Visual Studio Online
Introduction to Visual Studio OnlineIntroduction to Visual Studio Online
Introduction to Visual Studio Online
 
Git si o Git No
Git si o Git NoGit si o Git No
Git si o Git No
 
Testing
TestingTesting
Testing
 
Come Organizzare il proprio Team Project
Come Organizzare il proprio Team ProjectCome Organizzare il proprio Team Project
Come Organizzare il proprio Team Project
 
Git Perchè Usarlo
Git Perchè UsarloGit Perchè Usarlo
Git Perchè Usarlo
 

Dernier

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Dernier (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Unit Testing

  • 1. Unit testing in Visual Studio 2010 Because it is a matter of quality!!!
  • 2. Different Type of Tests Automated tests aimed to verify the functionality of a little piece of code, run very often by developers and from automated build. Unit Tests Test Suites managed with Microsoft Test Manager, manually executed from testers and associated with User Stories. Can be automated with Action Recording Manual Tests Web Request record and replay to simulate the interaction with web sites. Can be used to do load or stress test to verify the behavior of software under heavy usage Web Tests Record and replay user interaction with UI, plugin-based recorder to maximize reproducibility, generation of UiMap that contains all the data used to reproduce the automation. Coded UI Tests
  • 3. Test and Lifecycle - Waterfall Requirements Design Develop Test Deploy In waterfall processes testing has a well-defined phase, located between Develop and Deploy. With such a process developers tend to do manual test to verify that requirements are satisfied Modern waterfall approaches tend to distribute testing in all the phases of the process.
  • 4. Test and Lifecycle - Waterfall Requirement are software artifacts that can be tested following basic principle of testing The purpose of testing a program is to find problems in it The purpose of finding problem is to get them fixed Requirements Test (Testing Computer Software – Cem Kaner et Al.) Requirements should be verified with stakeholders and users to verify that we are going to create the right software A mismatch between the program and its specification is an error in the program if and only if the specification exists and is correct A program that follows a terrible specification is terrible not perfect (Testing Computer Software – Cem Kaner et Al.)
  • 5. Test and Lifecycle - Waterfall Even with Emerging Architecture you need to validate the design of the software. The design phase should produce a «proof of concept» for each «typical» part of the software Early testing on POC should be used to validate the infrastructure Design Test Technique used: Unit Test, Performance Test Testing of the Design phase should take place when:  No existing architecture, start from scratch  First project with new technology  Strict performance requirements  External service  Verify testability of the architecture
  • 6. Test and Lifecycle - Waterfall During developement all form of testing are used Unit test: used by developers to validate new code Manual test: Used by test team to validate code for «done» requirements Coded UI test: Used by developers and test team to automate testing through the interface Develop Test The main purpose of testing during development is guarantee quality of the codebase. When code is out of the developing phase, it should be ready to be “beta tested” to find bug that are not caught during development.
  • 7. Test and Lifecycle - Waterfall Testing phase is where you find bug during real- usage of the software The software is usually in «beta» stage, meaning that Real-usage Formal bugfix it can be used by real user. This is the moment where you mainly use Acceptance test with Microsoft Test Manager Develop Quality All defect found during this phase should be filled up in issue/bug tracker to be investigated by the team No developer should be allowed to «pick a bug» to fix it without a formal review. The aim of this phase is to fix all most important bugs of the software, as well as gather user impression of the overall product, to make little modification before the real shipping. All steps should be reported.
  • 8. Test and Lifecycle - Agile Requirements Design Develop Test Deploy Each agile process has its own development cycle, but quite all of them have an interactive cycle Each interaction value is added to the software and this value should be immediately available to Stakeholders Acceptance and Unit Testing are the skeleton of this lifecycle, without tests it is difficult to be really Agile. Testing permits to  Establish Definition Of Done (Acceptance)  Refactor and do incremental development (Unit testing)  Clarify User Stories (Acceptance)  Assure internal quality of the codebase (Unit testing in CI)
  • 9. Unit Testing xUnit test pattern and typical techniques of unit testing in VS2010
  • 10. Unit test principle Automated: Test can be executed without user interaction Integrated: Written in the same language of the code to test, available in the same environment Develop Standard: Many frameworks available Develop Agile: Support for refactoring and agile lifecycle Develop Pattern support: www.xunitpattern.org estabilish a ground language and series of pattern for unit testing in all language/environments
  • 11. xUnit framework pattern Setup: Initial conditions are set to maximize reproducibility of the test Setup Exercise: Code to be tested is executed, usually is a call to a single function or a series of calls. Exercise Verify: An expectation is checked, if the expectation fails, the whole test is considered to be failed Verify Teardown: If the test modify the system/environment everything is restored to a good / clean state Teardown
  • 12. Quality of good tests Automated: Test can be executed without user interaction Indipendent: The test does not depend on any other test Develop Focused: The test should verify a single condition Develop Repetable: Test depends only on precondition contained in the setup phase and it should give the same result at each execution Develop Fast: Slow tests are not executed frequently
  • 13. Test is First-Class code Part of the project: testing code has the same importance of tested code Part of the project Refactored: Time is spent refactoring and adapting test code to the modifications of tested code. Refactored Time: writing good tests takes time  but having good Unit Test suite dramatically raise quality  Hard to write Long run ROI: Sadly enough, Unit Testing usually does not pay in the short time, so it is difficult to take the path to unit testing Plan for the future
  • 14. DEMO Basic of 4-phase test in Visual Studio 2010
  • 15. Test smells Symptom: too much time to maintain tests Impact: test are not executed and removed from suite Cause: Code duplication, low quality test code High maintenance Symptom: test fails but the code under test is correct Impact: time wasted to look for inexistent bugs Cause: Test is too complex Buggy tests Symptom: test has conditional logic inside Impact: it is not clear what it is testing Cause: Dependence from environment, wrong logic Conditional test logic Symptom: it is difficult to understand what is tested Impact: it is difficult to understand why it failed Cause: Eager test, mystery guest, irrelevant Obscure test information, hard coded test data
  • 16. Avoid test smells Users does not execute the test often Continuous integration automatically executes tests Develop Test are slow, they needs several minutes to be executed Develop Categorized test permits execution of only a little part of a test, continuous test tools (Mighty Moose, Test Impact) can automate this Develop Manual intervention before test run Develop Write unit test first, write test that is testable
  • 17. Fixture The most difficult part to create Unit Tests without smells is fixture management
  • 18. The fixture Everything is needed to create preconditions for the execution of test, it can be data in database, setting global variables, cleaning up file on disks, etc. Setup Exercise This is the most complex part of the whole Unit- Testing stuff, because it is the source of many smell Verify Teardown Fresh Fixture – transient: The fixture is recreated at each test, at the end of the test the system is restored to the original state Fresh Fixture – persistent: Same as transient, but the system is not restored at the end of the test Shared Fixture: The fixture is shared for many test, it is created, then a series of test is executed
  • 19. Fresh transient Fixture is created during the setup phase, take track of every Setup modification that is done to the system. It is useful to create a mechanism that permits to schedule automatic cleanup at the end of the test. Exercise Verify Fixture is removed during the teardown phase, everything is Teardown restored. Garbage collector should not be used because it is not- deterministic. If multiple restore operations should be executed, use try- catch clause to be sure to cleanup the most of them
  • 20. Fresh persistent Fixture is created during the setup phase, no need to track Setup operations Next test will create another fixure, but every Exercise Setup modification done by the previous test is still there This can augment the risk of interacting-test Verify Exercise smell. This technique is useful only if we are sure that Teardown Verify the fresh persistent fixture will not impact other tests. It is useful mainly if the restore operation is Teardown slow and you do not want to lose time.
  • 21. Shared fixture Fixture is created during the setup phase, modification are Setup tracked First test is executed, the test is composed only by Exercise Exercise and Verify steps Subsequent tests execution will use the same Verify Exercise Setup fixture Verify Exercise Setup Verify Exercise Setup After the latest verification the fixture is removed. Teardown Verify Teardown
  • 22. Shared fixture Fixture Setup Setup Setup Setup Exercise Exercise Exercise Verify Verify Verify Teardown Teardown Teardown Teardown A shared fixture is created before the execution of each test Each test can create another specific fixture and remove it in Setup/Teardown After the latest test of the suite is executed the final Teardown is run to remove the shared fixture.
  • 23. Assertion How to write good verification code that maximize the advantage of unit testing
  • 24. Assertion Single assertion: A test should verify only one fact of the code under test Clear assertion: Reading verification code should immediately clarify what fact we are testing Develop Test named assertion: Name of the test should clarify the purpose and what is verified by the test.
  • 25. Writing good assertions Too many assertions in the test Expected Object, create an object that reflect the status you want to check, name that object in clear way. Develop Complex assertion code, that is not readable. Develop Use FluentInterface based assertion frameworks (SharpTestEx) Develop Magic values to verify return values or object properties Develop Use good names for variables and expected values
  • 26. Test doubles Creates fake component to be sure to exercise only a single part of the system
  • 27. Depend On Component The System Under Test dialogates with external Setup component and the verification phase has not access to it. Exercise Verify SUT DOC Teardown If the test fails, we are not sure if the reason is in bug in the SUT or for a bug or different behavior of the DOC. It leads to erratic test and frequent debugging test smell.
  • 28. Test Double Setup Test Double Exercise Verify SUT Teardown We need to design the SUT to loose coupling with the DOC, with this technique you can create a double of the DOC in the test. The Test Double simulates the real component, but it has a well defined and reproducible behavior that is defined in the Setup phase
  • 29. Verifiable Test Double Setup Test Double Exercise Verify SUT Teardown With a verifiable Test Double the Verify step can ask to Test Double to verify how the SUT interacted with him during Exercise phase. As an example, if you create a Test Double of an E-Mail sender component, you can verify that during Exercise the SUT asked to send an E-Mail.
  • 30. Types of TestDoubles Stub: its only purpose is to answer to the requests of the SUT with well defined and known answers, or with a default one Stub Dummy: It does nothing, simply avoid the SUT to crash for missing components. Dummy Mock and Spy: Behave like a Stub, but also permits to make assertion on how the SUT interacted with them. Mock Object and Test Spy Fake Object: It implements a DOC with minimal functionality. Fake Object
  • 31. Database Testing Testing a database is complex and needs specific techniques
  • 32. Database Testing Basic Sandbox: Each tester/environment should have a dedicated database to execute testing. Minimize dependency, maximize execution time avoid conflicts Database Sandbox Database Fixture: Shared fixture to minimize setup time, use of Back Door Manipulation and backup/restore attach/detach method. Heavy use of Fixture Setup Shared Fixture. Smart teardown: Use preload at each test and make every test transactional so you can rollback after each verification phase Teardown Database Projects: Specific project type introduced with VS2008 that contains a dedicated section to unit testing. Database Project