SlideShare una empresa de Scribd logo
1 de 11
Dev Unit Testing:
CppUnit Workshop


Mudabbir Warsi (SHAMU04)
December 29,2010
Agenda

• Introduction to Unit Testing
• Introduction to CppUnit
• Important aspects of CppUnit
  • Writing Test Cases
  • Launching Tests
  • Collecting and Reporting Test Results
• CppUnit Workshop
  • Demo
  • How to write unit tests for existing code?
  • Integration with the Build process
• Introduction to Stubs and Mock objects
• Q&A
   2   December 29, 2010 Copyright ©2010 CA. All rights reserved.
Introduction

• Traditional testing methods
    • Stepping through a debugger
    • Littering code with stream out put calls

• What is a “Unit Test”?
    “A Unit Test is a piece of code written by a developer that exercises a very small, specific area of
    functionality of the code being tested”.
•    Why Unit Testing?
    • Speed up the development – Write tests once, use tests to find errors many times
    • Less time spent on debugging – Incorrect changes discovered immediately
    • Tests as documentation. Provides a working specification of the functional code
    • Gain Confidence in your code
•    Excuses for NOT (Unit) testing?
    • It takes too much time to write the tests
    • I am being paid to write code, not to write tests
    • I feel guilty about putting QA staff out of work
    3    December 29, 2010 Copyright ©2010 CA. All rights reserved.
Introduction to CppUnit

• Trivia
    •   Kent Beck published the first unit test framework for SmallTalk in 1999
    •   CppUnit is a member of xUnit family (SUnit, JUnit, NUnit, pyUnit, vbUnit etc)
    •   CppUnit started as a port of JUnit to C++ by Michael Feathers
    •   Motto of CppUnit: “Testing: Early, Often and Automated”


• Important Classes of xUnit Framework
    •   TestCase                  : Represents a single test case
    •   TestSuite                 : A collection of Test Cases
    •   TestRunner                : A Launcher of Test Suites
    •   TestResult                : Collects errors/failures that occur during a test

    •   TestListener              : Listener of events that occur during a test




   4    December 29, 2010 Copyright ©2010 CA. All rights reserved.
Writing Test Cases


•   Class “Test” represents one individual test. All test cases
    should be a sub-class of Test. Its an Abstract base class.
                                                                      Test
•   Class “TestFixture” provides a common                             run(TestResult*):void
    environment OR common resources for a set of                                                  TestFixture
    test cases.
                                                                             TestLeaf         Setup()
                                                                                              TearDown()
•   Class “TestLeaf” is a base class for single test case. A
    test that is not composed of other test cases.                           TestCase

                                                                      run(TestResult*):void
                                                                      runTest() : void

•   Class “TestCase” is the parent of all Unit Tests. All
    unit tests should inherit from this class and should                  MyTestCase

    override the runTest() method                                     runTest() : void




     5   December 29, 2010 Copyright ©2010 CA. All rights reserved.
Writing Test Cases….Contd


•   A Test Suite is a container that collects several tests and runs them as a single unit.


•   Class “TestComposite” represents a                                                                  Test
                                                                                       1..*
    base class for collection of test cases.
                                                                                                 run(TestResult*):void
    Subclass this to implement a custom
    Test Suite.
                                                                                                      TestComposite

•   Class “TestSuite” represents a                                                               run(TestResult*) : void

    collection of Test Cases that are run as
    a single unit.
                                                                                TestSuite                                       MyTestSuite

                                                                           addTest(Test*) : void                           addTest(Test*) : void
                                                                       1   doGetChildTestAt(int) : Test*                   doGetChildTestAt(int) : Test*

                                                                           vector<Test*> suite                             deque<Test*> suite




     6    December 29, 2010 Copyright ©2010 CA. All rights reserved.
Launching Tests with TestRunner


• Class “TestRunner” executes the test cases and provides statistical information
  regarding the outcome of the test execution.
• CppUnit provides different test runners.
       •   TestRunner                 : Generic test runner
       •   TextTestRunner             : A text mode test runner
       •   MFCTestRunner : GUI based test runner
       •   QTTestRunner               : GUI based test runner for QT framework



• Unlike other elements of the framework, CppUnit does not provide any interface
  for creating custom Test Runners.

• Important method of TestRunner Class
    TestRunner::run(TestResult&); // Runs the test using the specified controller

   7       December 29, 2010 Copyright ©2010 CA. All rights reserved.
Collecting and Reporting Test Results


• Collecting Results with TestResult
   A TestResult collects the results of executing a collection of test cases. It counts the tests run and
   collects the failures and errors so that the framework can report them.


• Observing Results with TestListeners
   TestListeners provides the ability for the Framework users to be notified about the different events
   that occur while execution of a test case.
   Eg: Start of a test case, end of a test case, start of test suite, End of a test suite

• Printing Results with Outputters
   Outputters print the summary of the Test Results in various formats (XML Format, Text Format etc).
   It can be extended to print result summary in any custom format.
   Eg: TextOutputter, XmlOutputter, CompilerOutputter




    8    December 29, 2010 Copyright ©2010 CA. All rights reserved.
CppUnit Workshop


• DEMO
• How to write unit tests for existing code?
• Integration with the Build process




    9   December 29, 2010 Copyright ©2010 CA. All rights reserved.
Introduction to Stubs and MOCK objects

•   Stub is a piece of code that replaces the real code, in order to isolate the calling code from the real
    implementation.
     •    Advantages of STUBS
           • Replace complex behavior with a simple one
           • Allows for coarse-grained Isolation
     •    Disadvantages of STUBS
           • Complex to write
           • Difficult to debug and maintain

•   A Mock object is an object created to stand in for an object that the code being tested will be
    collaborating with.
     •    Advantages of MOCK objects
           •     Easier to write and maintain.
           •     Allows for fine-grained Isolation

     •    Disadvantages of MOCK objects
           • There may be many objects to Mock
           • Forces to re write some of the code under test.
     10   December 29, 2010 Copyright ©2010 CA. All rights reserved.
Thank You !!

Más contenido relacionado

La actualidad más candente

Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and SpringVMware Tanzu
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytestHector Canto
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingJoe Tremblay
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google MockICS
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With PythonSiddhi
 
Test unitaire
Test unitaireTest unitaire
Test unitaireIsenDev
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkArulalan T
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
05 junit
05 junit05 junit
05 junitmha4
 

La actualidad más candente (20)

Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Junit
JunitJunit
Junit
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Test unitaire
Test unitaireTest unitaire
Test unitaire
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
05 junit
05 junit05 junit
05 junit
 
Selenium WebDriver FAQ's
Selenium WebDriver FAQ'sSelenium WebDriver FAQ's
Selenium WebDriver FAQ's
 

Destacado

Nunit C# source code defects report by Parasoft dotTEST
Nunit  C# source code  defects report by Parasoft dotTEST Nunit  C# source code  defects report by Parasoft dotTEST
Nunit C# source code defects report by Parasoft dotTEST Engineering Software Lab
 
Parasoft Concerto A complete ALM platform that ensures quality software can b...
Parasoft Concerto A complete ALM platform that ensures quality software can b...Parasoft Concerto A complete ALM platform that ensures quality software can b...
Parasoft Concerto A complete ALM platform that ensures quality software can b...Engineering Software Lab
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis Engineering Software Lab
 
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורה
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורהPerforce עשרת היתרונות המובילים של מערכת ניהול התצורה
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורהEngineering Software Lab
 
Amran Tuberi - the damage of cycling to the desert ecosystem
Amran Tuberi - the damage of cycling to the desert ecosystemAmran Tuberi - the damage of cycling to the desert ecosystem
Amran Tuberi - the damage of cycling to the desert ecosystemEngineering Software Lab
 
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011Engineering Software Lab
 
Code coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspectiveCode coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspectiveEngineering Software Lab
 
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++TestEngineering Software Lab
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective Engineering Software Lab
 
Digital Business: Communication and Collaboration Introduction
Digital Business: Communication and Collaboration IntroductionDigital Business: Communication and Collaboration Introduction
Digital Business: Communication and Collaboration IntroductionDigital Business
 

Destacado (20)

Parasoft fda software compliance part2
Parasoft fda software compliance   part2Parasoft fda software compliance   part2
Parasoft fda software compliance part2
 
Nunit C# source code defects report by Parasoft dotTEST
Nunit  C# source code  defects report by Parasoft dotTEST Nunit  C# source code  defects report by Parasoft dotTEST
Nunit C# source code defects report by Parasoft dotTEST
 
Introduction to Parasoft C++TEST
Introduction to Parasoft C++TEST Introduction to Parasoft C++TEST
Introduction to Parasoft C++TEST
 
Parasoft fda software compliance part1
Parasoft fda software compliance   part1Parasoft fda software compliance   part1
Parasoft fda software compliance part1
 
Parasoft Concerto A complete ALM platform that ensures quality software can b...
Parasoft Concerto A complete ALM platform that ensures quality software can b...Parasoft Concerto A complete ALM platform that ensures quality software can b...
Parasoft Concerto A complete ALM platform that ensures quality software can b...
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורה
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורהPerforce עשרת היתרונות המובילים של מערכת ניהול התצורה
Perforce עשרת היתרונות המובילים של מערכת ניהול התצורה
 
A Scalable Software Build Accelerator
A Scalable Software Build AcceleratorA Scalable Software Build Accelerator
A Scalable Software Build Accelerator
 
Amran Tuberi - the damage of cycling to the desert ecosystem
Amran Tuberi - the damage of cycling to the desert ecosystemAmran Tuberi - the damage of cycling to the desert ecosystem
Amran Tuberi - the damage of cycling to the desert ecosystem
 
המסדרת הפכה למגוהצת
המסדרת הפכה למגוהצתהמסדרת הפכה למגוהצת
המסדרת הפכה למגוהצת
 
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011
WPF/ XamDataGrid Performance, Infragistics Seminar, Israel , November 2011
 
Palamida Open Source Compliance Solution
Palamida Open Source Compliance Solution Palamida Open Source Compliance Solution
Palamida Open Source Compliance Solution
 
Code coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspectiveCode coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspective
 
FDA software compliance 2016
FDA software compliance 2016FDA software compliance 2016
FDA software compliance 2016
 
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
 
Embedded System Test Automation
Embedded System Test AutomationEmbedded System Test Automation
Embedded System Test Automation
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective
 
Sykemittari
SykemittariSykemittari
Sykemittari
 
Digital Business: Communication and Collaboration Introduction
Digital Business: Communication and Collaboration IntroductionDigital Business: Communication and Collaboration Introduction
Digital Business: Communication and Collaboration Introduction
 
Что растёт на подоконнике
Что растёт на подоконникеЧто растёт на подоконнике
Что растёт на подоконнике
 

Similar a Cpp unit

Similar a Cpp unit (20)

Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
Junit
JunitJunit
Junit
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Test ng
Test ngTest ng
Test ng
 
Junit
JunitJunit
Junit
 
Junit
JunitJunit
Junit
 
Plone Testing Tools And Techniques
Plone Testing Tools And TechniquesPlone Testing Tools And Techniques
Plone Testing Tools And Techniques
 
J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementations
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
 
Unit testing
Unit testingUnit testing
Unit testing
 

Último

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Último (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Cpp unit

  • 1. Dev Unit Testing: CppUnit Workshop Mudabbir Warsi (SHAMU04) December 29,2010
  • 2. Agenda • Introduction to Unit Testing • Introduction to CppUnit • Important aspects of CppUnit • Writing Test Cases • Launching Tests • Collecting and Reporting Test Results • CppUnit Workshop • Demo • How to write unit tests for existing code? • Integration with the Build process • Introduction to Stubs and Mock objects • Q&A 2 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 3. Introduction • Traditional testing methods • Stepping through a debugger • Littering code with stream out put calls • What is a “Unit Test”? “A Unit Test is a piece of code written by a developer that exercises a very small, specific area of functionality of the code being tested”. • Why Unit Testing? • Speed up the development – Write tests once, use tests to find errors many times • Less time spent on debugging – Incorrect changes discovered immediately • Tests as documentation. Provides a working specification of the functional code • Gain Confidence in your code • Excuses for NOT (Unit) testing? • It takes too much time to write the tests • I am being paid to write code, not to write tests • I feel guilty about putting QA staff out of work 3 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 4. Introduction to CppUnit • Trivia • Kent Beck published the first unit test framework for SmallTalk in 1999 • CppUnit is a member of xUnit family (SUnit, JUnit, NUnit, pyUnit, vbUnit etc) • CppUnit started as a port of JUnit to C++ by Michael Feathers • Motto of CppUnit: “Testing: Early, Often and Automated” • Important Classes of xUnit Framework • TestCase : Represents a single test case • TestSuite : A collection of Test Cases • TestRunner : A Launcher of Test Suites • TestResult : Collects errors/failures that occur during a test • TestListener : Listener of events that occur during a test 4 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 5. Writing Test Cases • Class “Test” represents one individual test. All test cases should be a sub-class of Test. Its an Abstract base class. Test • Class “TestFixture” provides a common run(TestResult*):void environment OR common resources for a set of TestFixture test cases. TestLeaf Setup() TearDown() • Class “TestLeaf” is a base class for single test case. A test that is not composed of other test cases. TestCase run(TestResult*):void runTest() : void • Class “TestCase” is the parent of all Unit Tests. All unit tests should inherit from this class and should MyTestCase override the runTest() method runTest() : void 5 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 6. Writing Test Cases….Contd • A Test Suite is a container that collects several tests and runs them as a single unit. • Class “TestComposite” represents a Test 1..* base class for collection of test cases. run(TestResult*):void Subclass this to implement a custom Test Suite. TestComposite • Class “TestSuite” represents a run(TestResult*) : void collection of Test Cases that are run as a single unit. TestSuite MyTestSuite addTest(Test*) : void addTest(Test*) : void 1 doGetChildTestAt(int) : Test* doGetChildTestAt(int) : Test* vector<Test*> suite deque<Test*> suite 6 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 7. Launching Tests with TestRunner • Class “TestRunner” executes the test cases and provides statistical information regarding the outcome of the test execution. • CppUnit provides different test runners. • TestRunner : Generic test runner • TextTestRunner : A text mode test runner • MFCTestRunner : GUI based test runner • QTTestRunner : GUI based test runner for QT framework • Unlike other elements of the framework, CppUnit does not provide any interface for creating custom Test Runners. • Important method of TestRunner Class TestRunner::run(TestResult&); // Runs the test using the specified controller 7 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 8. Collecting and Reporting Test Results • Collecting Results with TestResult A TestResult collects the results of executing a collection of test cases. It counts the tests run and collects the failures and errors so that the framework can report them. • Observing Results with TestListeners TestListeners provides the ability for the Framework users to be notified about the different events that occur while execution of a test case. Eg: Start of a test case, end of a test case, start of test suite, End of a test suite • Printing Results with Outputters Outputters print the summary of the Test Results in various formats (XML Format, Text Format etc). It can be extended to print result summary in any custom format. Eg: TextOutputter, XmlOutputter, CompilerOutputter 8 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 9. CppUnit Workshop • DEMO • How to write unit tests for existing code? • Integration with the Build process 9 December 29, 2010 Copyright ©2010 CA. All rights reserved.
  • 10. Introduction to Stubs and MOCK objects • Stub is a piece of code that replaces the real code, in order to isolate the calling code from the real implementation. • Advantages of STUBS • Replace complex behavior with a simple one • Allows for coarse-grained Isolation • Disadvantages of STUBS • Complex to write • Difficult to debug and maintain • A Mock object is an object created to stand in for an object that the code being tested will be collaborating with. • Advantages of MOCK objects • Easier to write and maintain. • Allows for fine-grained Isolation • Disadvantages of MOCK objects • There may be many objects to Mock • Forces to re write some of the code under test. 10 December 29, 2010 Copyright ©2010 CA. All rights reserved.