SlideShare uma empresa Scribd logo
1 de 20
Unit Test Exp
Hieu T. Le
What is Unit Test?
What is a GOOD unit test?
‱ Automatic
‱ Thorough
‱ Repeatable
‱ Independent
‱ Professional
Unit Test Framework
‱ Provide a framework to
– Initialize/shutdown unit test environment
– Automated check fail/pass
‱ http://en.wikipedia.org/wiki/List_of_unit_test
ing_frameworks
– JUnit, CppUnit, CUnit, PhpUnit, NUnit, 

Unit Test Difficulties
‱ Test Case Generate
‱ Test Data Generate
‱ Environment
‱ Framework
‱ Effort vs. Schedule
‱ Thinking
‱ Process
Unit Test Environment
‱ Language: C, C++, Java
‱ Platform: Linux
‱ Framework: CppUnit, CUnit, JUnit, Google Test
‱ Tools: GCov, LCov, Jenkins
PROJECT A – PHASE 1
Language: C
Platform: vxWorks (Linux simulator)
Project A – Phase 1
‱ Difficulties
– Newbie team member
– Input return boolean, many alternatives path
– No hardware, use stub for many
vxWorks/hardware relating
– Schedule rush
Project A – Phase 1
‱ How can we work out?
– Experienced engineer build up unit test
framework for project
– Engineer does
‱ Basic test case: good case, bad case
‱ Additional test case for each code path
‱ Test data
‱ Verify result
Project A – Phase 1
‱ Lesson learnt
– It is bad when we focus too much into alternative
cases
– It is bad when we focus too much into unit test
coverage
– Unit test cannot be verified manually by eyes
PROJECT A – PHASE 2
Language: C
Platform: vxWorks (Linux simulator)
Project A – Phase 2
‱ Difficulties (from Phase 1)
– Unit test is verified manually
– Too many alternative cases
– Test data generating
Project A – Phase 2
‱ How can we work out?
– Experienced engineer refactor unit test framework
of phase 1
‱ Setup mechanism to ASSERT and automation
‱ Setup mechanism to automated generate test data
– Engineer does
‱ Run tool to generate test data for good/bad case
‱ Write additional test case for some alternatives code
path
Project A – Phase 2
‱ Lesson learnt
– Use tool to generate test data automatically
– Some engineer setup data without resetting it, it
makes other test case fail
– Should setup framework for mock object
– Should enforce fixing fail test case ASAP
PROJECT B
Language: Java, JNI, C++
Platform: Embedded Linux (cross run on PC)
Project B
‱ Difficulties
– Full stack application run on embedded board
which contains reference to many components
– Boot up time is long
– Cannot initialize all components for testing since it
depending on hardware
– Cannot run component standalone
– Cannot run on desktop PC
Project B
Project B
‱ How can we solve it?
– Experienced engineer setup a framework of unit
test using mock object approach
‱ Write mock object to wrap some components which
has many dependencies and depending on hardware
– Engineer does
‱ Write test case for the test component using developed
mock object
Project B
Mock Object
Project B
‱ Lesson learnt
– Use mock object so that we can control the result
– Use mock object to wrap some hardware
depending component
‱ Technologies used:
– Junit
– JMockit, Mockito
Thank You

Mais conteĂșdo relacionado

Mais procurados

A Taste of Pharo 7.0
A Taste of Pharo 7.0A Taste of Pharo 7.0
A Taste of Pharo 7.0
ESUG
 

Mais procurados (20)

Vagrant+Rouster at salesforce.com
Vagrant+Rouster at salesforce.comVagrant+Rouster at salesforce.com
Vagrant+Rouster at salesforce.com
 
Auto Deploy Deep Dive – vBrownBag Style
Auto Deploy Deep Dive – vBrownBag StyleAuto Deploy Deep Dive – vBrownBag Style
Auto Deploy Deep Dive – vBrownBag Style
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Modules of the twenties
Modules of the twentiesModules of the twenties
Modules of the twenties
 
Puppet evolutions
Puppet evolutionsPuppet evolutions
Puppet evolutions
 
Applying software engineering to configuration management
Applying software engineering to configuration managementApplying software engineering to configuration management
Applying software engineering to configuration management
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
Foundations of Zend Framework
Foundations of Zend FrameworkFoundations of Zend Framework
Foundations of Zend Framework
 
Testing in-python-and-pytest-framework
Testing in-python-and-pytest-frameworkTesting in-python-and-pytest-framework
Testing in-python-and-pytest-framework
 
Puppet Camp Paris 2016 Data in Modules
Puppet Camp Paris 2016 Data in ModulesPuppet Camp Paris 2016 Data in Modules
Puppet Camp Paris 2016 Data in Modules
 
A Taste of Pharo 7.0
A Taste of Pharo 7.0A Taste of Pharo 7.0
A Taste of Pharo 7.0
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Command Line Arguments with Getopt::Long
Command Line Arguments with Getopt::LongCommand Line Arguments with Getopt::Long
Command Line Arguments with Getopt::Long
 
Expressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework Blastoff
 
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, PuppetPuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
PuppetConf 2016: The Future of Testing Puppet Code – Gareth Rushgrove, Puppet
 
Tp install anything
Tp install anythingTp install anything
Tp install anything
 

Semelhante a Unit test

May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and Challenges
TriTAUG
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 

Semelhante a Unit test (20)

Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and Challenges
 
May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and Challenges
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
 
Effective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and DapperEffective .NET Core Unit Testing with SQLite and Dapper
Effective .NET Core Unit Testing with SQLite and Dapper
 
Continuous Integration: Improving Quality in Moodle
Continuous Integration: Improving Quality in Moodle Continuous Integration: Improving Quality in Moodle
Continuous Integration: Improving Quality in Moodle
 
KrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdfKrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdf
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
Winning the battle against Automated testing
Winning the battle against Automated testingWinning the battle against Automated testing
Winning the battle against Automated testing
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Hudson
HudsonHudson
Hudson
 
The QA/Testing Process
The QA/Testing ProcessThe QA/Testing Process
The QA/Testing Process
 
Test parallelization using Jenkins
Test parallelization using JenkinsTest parallelization using Jenkins
Test parallelization using Jenkins
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 
XPDays-2018
XPDays-2018XPDays-2018
XPDays-2018
 
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
 
The Test way
The Test wayThe Test way
The Test way
 

Mais de Hieu Le Trung (10)

[Hotshare.us]sat thu dau_mung_mu-thanhphong
[Hotshare.us]sat thu dau_mung_mu-thanhphong[Hotshare.us]sat thu dau_mung_mu-thanhphong
[Hotshare.us]sat thu dau_mung_mu-thanhphong
 
Open source-options-v1
Open source-options-v1Open source-options-v1
Open source-options-v1
 
Confluence vs. TWiki
Confluence vs. TWikiConfluence vs. TWiki
Confluence vs. TWiki
 
Model For Applying Unit Test
Model For Applying Unit TestModel For Applying Unit Test
Model For Applying Unit Test
 
Introduction To GCS' EMB Division
Introduction To GCS' EMB DivisionIntroduction To GCS' EMB Division
Introduction To GCS' EMB Division
 
Microsoft Sync Framework
Microsoft Sync FrameworkMicrosoft Sync Framework
Microsoft Sync Framework
 
2 Effective Manufacturing Erp Mes
2 Effective Manufacturing Erp Mes2 Effective Manufacturing Erp Mes
2 Effective Manufacturing Erp Mes
 
Global CyberSoft - MES Introduction
Global CyberSoft - MES IntroductionGlobal CyberSoft - MES Introduction
Global CyberSoft - MES Introduction
 
Virtualization & Global CyberSoft
Virtualization & Global CyberSoftVirtualization & Global CyberSoft
Virtualization & Global CyberSoft
 
Enterprise Project Management at Global CyberSoft
Enterprise Project Management at Global CyberSoftEnterprise Project Management at Global CyberSoft
Enterprise Project Management at Global CyberSoft
 

Último

Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Unit test

  • 2. What is Unit Test? What is a GOOD unit test? ‱ Automatic ‱ Thorough ‱ Repeatable ‱ Independent ‱ Professional
  • 3. Unit Test Framework ‱ Provide a framework to – Initialize/shutdown unit test environment – Automated check fail/pass ‱ http://en.wikipedia.org/wiki/List_of_unit_test ing_frameworks – JUnit, CppUnit, CUnit, PhpUnit, NUnit, 

  • 4. Unit Test Difficulties ‱ Test Case Generate ‱ Test Data Generate ‱ Environment ‱ Framework ‱ Effort vs. Schedule ‱ Thinking ‱ Process
  • 5. Unit Test Environment ‱ Language: C, C++, Java ‱ Platform: Linux ‱ Framework: CppUnit, CUnit, JUnit, Google Test ‱ Tools: GCov, LCov, Jenkins
  • 6. PROJECT A – PHASE 1 Language: C Platform: vxWorks (Linux simulator)
  • 7. Project A – Phase 1 ‱ Difficulties – Newbie team member – Input return boolean, many alternatives path – No hardware, use stub for many vxWorks/hardware relating – Schedule rush
  • 8. Project A – Phase 1 ‱ How can we work out? – Experienced engineer build up unit test framework for project – Engineer does ‱ Basic test case: good case, bad case ‱ Additional test case for each code path ‱ Test data ‱ Verify result
  • 9. Project A – Phase 1 ‱ Lesson learnt – It is bad when we focus too much into alternative cases – It is bad when we focus too much into unit test coverage – Unit test cannot be verified manually by eyes
  • 10. PROJECT A – PHASE 2 Language: C Platform: vxWorks (Linux simulator)
  • 11. Project A – Phase 2 ‱ Difficulties (from Phase 1) – Unit test is verified manually – Too many alternative cases – Test data generating
  • 12. Project A – Phase 2 ‱ How can we work out? – Experienced engineer refactor unit test framework of phase 1 ‱ Setup mechanism to ASSERT and automation ‱ Setup mechanism to automated generate test data – Engineer does ‱ Run tool to generate test data for good/bad case ‱ Write additional test case for some alternatives code path
  • 13. Project A – Phase 2 ‱ Lesson learnt – Use tool to generate test data automatically – Some engineer setup data without resetting it, it makes other test case fail – Should setup framework for mock object – Should enforce fixing fail test case ASAP
  • 14. PROJECT B Language: Java, JNI, C++ Platform: Embedded Linux (cross run on PC)
  • 15. Project B ‱ Difficulties – Full stack application run on embedded board which contains reference to many components – Boot up time is long – Cannot initialize all components for testing since it depending on hardware – Cannot run component standalone – Cannot run on desktop PC
  • 17. Project B ‱ How can we solve it? – Experienced engineer setup a framework of unit test using mock object approach ‱ Write mock object to wrap some components which has many dependencies and depending on hardware – Engineer does ‱ Write test case for the test component using developed mock object
  • 19. Project B ‱ Lesson learnt – Use mock object so that we can control the result – Use mock object to wrap some hardware depending component ‱ Technologies used: – Junit – JMockit, Mockito

Notas do Editor

  1. Process: follow up with failed test case immediately.