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
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