Ten things you should know when writing good unit test cases
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Ten things you should know when writing good unit test cases

on

  • 2,145 views

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

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.

Statistics

Views

Total Views
2,145
Views on SlideShare
2,144
Embed Views
1

Actions

Likes
1
Downloads
34
Comments
0

1 Embed 1

http://localhost 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ten things you should know when writing good unit test cases Presentation Transcript

  • 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. © 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. © 2013 IBM Corporation Who are we?  Paul Thwaite – QA Engineer, IBM  Stuart Marks – Principal Member of Technical Staff, Oracle
  • 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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. © 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