WHY BOTHER TO UNIT TEST Suprinder Pujji
OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing Who Should Unit Test A Case Study Conclusion
WHAT IS UNIT TESTING Lowest level of testing performed - Individual units of software are tested – Example - –Function or subroutine in structured Programming Language –Class in an object oriented language –Menu or display in a 4GL
EMPHASIS OF UNIT TESTING Have to be repeated - All tests have to be maintained –
BENEFITS OF UNIT TESTING Test parts of a project without waiting for the other parts to be available, Achieve parallelism in testing Able to detect and remove defects at a much less cost compared to other later stages of testing, Simplifies debugging Tests internal conditions that are not easily reached by external inputs
Popular Misconceptions Prevailing It consumes too much time Integration Tests will catch all the Bugs Anyway I’m too good a Programmer to Need Unit tests It only proves that the code does what the code does It is not Cost Effective
Who Should do it Unit Testing focuses on implementation Should be done by Test designers Test Designers should know the System requirements and design thoroughly. Test Designer should be more experienced Should be independent
WORK FLOW USING TEST CASES
CASE STUDY Analysis of the Integration Testing and System Testing bugs was done Found that about 30 % of bugs caught in the final stages could have been caught in the early stages it self.
CASE STUDY Adopted concept of Static Analysis on unit test cases 15 % reduction in the number of bugs escaping to the final stages of software development.
CASE STUDY Logical errors contributed to only 8 %. Found that % of logical defects caught in the static analysis phase increased to about 13 %.
CASE STUDY Without Using Unit Test Cases
CASE STUDY With Unit Test Cases
QUESTIONS FOR EVALUATING THE UNIT TESTING FOR ADEQUACY Have all the statements been exercised by at least one test Has each conditional statement been exercised at least once each way by the tests Have all boundary cases been exercised
QUESTIONS FOR EVALUATING THE UNIT TESTING FOR ADEQUACY Were any design assumptions made about the operation of this unit? Have the tests demonstrated these assumptions Have the tests exercised the unit over the full range of operational conditions it is expected to address
CONCLUSION Unit testing can be very effective and affordable. It will result in reduction of total efforts while simultaneously increasing the quality of the product significantly also reducing in the long-term maintenance cost and the total life cycle cost.