Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
• htt...
Unit Test Difficulties
• Test Case Generate
• Test Data Generate
• Environment
• Framework
• Effort vs. Schedule
• Thinkin...
Unit Test Environment
• Language: C, C++, Java
• Platform: Linux
• Framework: CppUnit, CUnit, JUnit, Google Test
• Tools: ...
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 ...
Project A – Phase 1
• How can we work out?
– Experienced engineer build up unit test
framework for project
– Engineer does...
Project A – Phase 1
• Lesson learnt
– It is bad when we focus too much into alternative
cases
– It is bad when we focus to...
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 dat...
Project A – Phase 2
• How can we work out?
– Experienced engineer refactor unit test framework
of phase 1
• Setup mechanis...
Project A – Phase 2
• Lesson learnt
– Use tool to generate test data automatically
– Some engineer setup data without rese...
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...
Project B
Project B
• How can we solve it?
– Experienced engineer setup a framework of unit
test using mock object approach
• Write ...
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
depe...
Thank You
Upcoming SlideShare
Loading in …5
×

Unit test

337 views

Published on

My C++, Java unit test development experience

Published in: Software
  • Hi there! Get Your Professional Job-Winning Resume Here - Check our website! http://bit.ly/resumpro
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Unit test

  1. 1. Unit Test Exp Hieu T. Le
  2. 2. What is Unit Test? What is a GOOD unit test? • Automatic • Thorough • Repeatable • Independent • Professional
  3. 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. 4. Unit Test Difficulties • Test Case Generate • Test Data Generate • Environment • Framework • Effort vs. Schedule • Thinking • Process
  5. 5. Unit Test Environment • Language: C, C++, Java • Platform: Linux • Framework: CppUnit, CUnit, JUnit, Google Test • Tools: GCov, LCov, Jenkins
  6. 6. PROJECT A – PHASE 1 Language: C Platform: vxWorks (Linux simulator)
  7. 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. 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. 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. 10. PROJECT A – PHASE 2 Language: C Platform: vxWorks (Linux simulator)
  11. 11. Project A – Phase 2 • Difficulties (from Phase 1) – Unit test is verified manually – Too many alternative cases – Test data generating
  12. 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. 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. 14. PROJECT B Language: Java, JNI, C++ Platform: Embedded Linux (cross run on PC)
  15. 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
  16. 16. Project B
  17. 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
  18. 18. Project B Mock Object
  19. 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
  20. 20. Thank You

×