17
WHY BOTHER TO UNIT TEST Suprinder Pujji

WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

Embed Size (px)

Citation preview

Page 1: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

WHY BOTHER TO UNIT TEST

Suprinder Pujji

Page 2: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

OVERVIEW

What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing Who Should Unit Test A Case Study Conclusion

Page 3: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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

Page 4: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

EMPHASIS OF UNIT TESTING

Have to be repeated -

All tests have to be maintained –

Page 5: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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

Page 6: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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

Page 7: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing
Page 8: 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 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

Page 9: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

WORK FLOW USING TEST CASES

Page 10: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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.

Page 11: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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.

Page 12: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

CASE STUDY

Logical errors contributed to only 8 %.

Found that % of logical defects caught in the static analysis phase increased to about 13 %.

Page 13: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

CASE STUDYWithout Using Unit Test Cases

Page 14: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

CASE STUDYWith Unit Test Cases

Page 15: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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

Page 16: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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

Page 17: WHY BOTHER TO UNIT TEST Suprinder Pujji. OVERVIEW What is Unit testing Emphasis of Unit testing Benefits of Unit Testing Popular Misconceptions Prevailing

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.