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.
© 2013 IBM Corporation
Paul Thwaite IBM, Stuart Marks Oracle.
BOF 4255
Ten Things You Should Know
When Writing Good Unit T...
© 2013 IBM Corporation
Important Disclaimers
THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL ...
© 2013 IBM Corporation
Who are we?
 Paul Thwaite
– QA Engineer, IBM
 Stuart Marks
– Principal Member of Technical Staff,...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
1. Think before you act
2. Make your tests understandable
3. Keep your tests “small and simple”
4. ...
© 2013 IBM Corporation
Over to you
 What are your experiences with unit testing ideals vs. real world?
 What testing pro...
© 2013 IBM Corporation16
Visit IBM booth #5112
 Visit the IBM booth 5112 for QA queries
–09:30 – 12:00
–Tuesday 24 Septem...
Upcoming SlideShare
Loading in …5
×

Ten things you should know when writing good unit test cases

3,074 views

Published on

A JavaOne BOF session on ten things you should know when writing good unit test cases. These ten simple rules will help guide developers to write solid unit tests which will be easy to run, debug and maintain.

Published in: Technology, Education
  • Be the first to comment

Ten things you should know when writing good unit test cases

  1. 1. © 2013 IBM Corporation Paul Thwaite IBM, Stuart Marks Oracle. BOF 4255 Ten Things You Should Know When Writing Good Unit Test Cases in Java Document number
  2. 2. © 2013 IBM Corporation Important Disclaimers THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS 2
  3. 3. © 2013 IBM Corporation Who are we?  Paul Thwaite – QA Engineer, IBM  Stuart Marks – Principal Member of Technical Staff, Oracle
  4. 4. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment
  5. 5. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment What are you testing? Why are you testing? Plan
  6. 6. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Comments Expected behaviour Aid debug Diagnostics
  7. 7. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Separate test logic / setup Much easier to debug Use setup / teardown
  8. 8. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment One scenario per test Enables fast debug Obvious why test failed
  9. 9. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Run unit tests often as possible Maintain quality bar Quick results
  10. 10. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Non-deterministic tests are a headache Fix intermittent tests immediately No value, waste of resource Must trust all tests
  11. 11. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Must run in any order Run subset, faster results No dependencies
  12. 12. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment Use message in asserts Make it simple to debug Reference input data Record test environment info
  13. 13. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment No ports, IP addresses, data files, databases Use config files, system properties or mock objects Portable tests
  14. 14. © 2013 IBM Corporation 1. Think before you act 2. Make your tests understandable 3. Keep your tests “small and simple” 4. Test one thing only 5. Fast tests only 6. Absolute repeatability 7. Independent tests only 8. Provide diagnostic data on failure 9. No hard-coding of your environment A passing test is a silent test Too much output = confusion Use option, config file to turn on debug, save output
  15. 15. © 2013 IBM Corporation Over to you  What are your experiences with unit testing ideals vs. real world?  What testing problems and pathologies have you encountered?  What are the root causes of your testing problems?  What is the cost of test maintenance?
  16. 16. © 2013 IBM Corporation16 Visit IBM booth #5112  Visit the IBM booth 5112 for QA queries –09:30 – 12:00 –Tuesday 24 September  Meet other IBM developers at JavaOne  Checkout what IBM is doing at JavaOne Tue 24 Sept, 09:30-12:00http://ibm.co/JavaOne

×