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

More Related Content

PDF
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
PDF
IBM Health Center Details
PDF
Impact2014: Introduction to the IBM Java Tools
PDF
JavaOne2013: Secure Engineering Practices for Java
ODP
Debugging Native heap OOM - JavaOne 2013
ODP
Windows Debugging Tools - JavaOne 2013
PPTX
IOUG Collaborate 2014 Auditing/Security in EM12c
PDF
Administration APIs: REST and JMX for IBM InfoSphere Streams V4.0
JavaOne2013: Build Your Own Runtime Monitoring for the IBM JDK with the Healt...
IBM Health Center Details
Impact2014: Introduction to the IBM Java Tools
JavaOne2013: Secure Engineering Practices for Java
Debugging Native heap OOM - JavaOne 2013
Windows Debugging Tools - JavaOne 2013
IOUG Collaborate 2014 Auditing/Security in EM12c
Administration APIs: REST and JMX for IBM InfoSphere Streams V4.0

What's hot (20)

PPTX
Em13c New Features- Two of Two
PDF
Em13c features- HotSos 2016
PDF
Ebs performance tuning session feb 13 2013---Presented by Oracle
PPT
Windows 7 For Geeks
PDF
DUG'20: 01 - Welcome & DAOS Update
PDF
Dell-EMC Remote Acess Controller "DRAC" 10 Features For "Power" Users
PPTX
Oracle licensing on VMware, Cloud, Hyper V and other virtualised platforms
PDF
Cloud Technology: Now Entering the Business Process Phase
PDF
Virtualization aware Java VM
PPTX
Best Practices with IPS on Oracle Solaris 11
PPTX
UKOUG APPS 14: Optimizing Performance for Oracle EPM Systems
PPTX
Om enterprise labs session leader
PPTX
Optimizing Oracle licensing in VMware environments
PPTX
The application model in real life
PDF
Understanding oracle certification_support_licensing_v_mware_environments
PPTX
Oracle Solaris 11 - Best for Enterprise Applications
PDF
IAITAM Webinar: How to Optimize Oracle licensing in VMware environments
PDF
Dhct config report
PDF
EDB Postgres Failover Manager
 
PDF
Oracle Database Licensing Rules
Em13c New Features- Two of Two
Em13c features- HotSos 2016
Ebs performance tuning session feb 13 2013---Presented by Oracle
Windows 7 For Geeks
DUG'20: 01 - Welcome & DAOS Update
Dell-EMC Remote Acess Controller "DRAC" 10 Features For "Power" Users
Oracle licensing on VMware, Cloud, Hyper V and other virtualised platforms
Cloud Technology: Now Entering the Business Process Phase
Virtualization aware Java VM
Best Practices with IPS on Oracle Solaris 11
UKOUG APPS 14: Optimizing Performance for Oracle EPM Systems
Om enterprise labs session leader
Optimizing Oracle licensing in VMware environments
The application model in real life
Understanding oracle certification_support_licensing_v_mware_environments
Oracle Solaris 11 - Best for Enterprise Applications
IAITAM Webinar: How to Optimize Oracle licensing in VMware environments
Dhct config report
EDB Postgres Failover Manager
 
Oracle Database Licensing Rules
Ad

Similar to Ten things you should know when writing good unit test cases (20)

PPTX
Fantastic Tests - The Crimes of Bad Test Design
PDF
End-to-End Automated Testing: Lessons from Zombieland
PPTX
Lessons Learned in Test Automation From Zombieland
PDF
Chaos Engineering - Limiting Damage During Chaos Experiments
PDF
Test Drive Development
PDF
Solving Flaky Automated Tests Using Machine Learning
PPT
SoftwareTesing_UNIT-1use it my teacher give it
PDF
The Developer’s Guide to Test Automation
PPTX
Curiosity software Ireland and Perfecto present: achieving in-sprint regressi...
PDF
The Survey Says: Testers Spend Their Time Doing...
PPTX
Dba tips and_tricks
PDF
DevOps in Practice: When does "Practice" Become "Doing"?
PPTX
6 Easy Steps to Write Test Cases
PPTX
Insoft training day_1
PDF
Clean & Dirty Acceptance Tests with Cucumber & Watir
PDF
Applying principles of chaos engineering to serverless (O'Reilly Software Arc...
PDF
Exploring Best Practises in Design of Experiments: A Data Driven Approach to ...
PDF
You have no idea what your users want - WordCamp PDX
PDF
Nevera Dul Moment
PDF
Oracle Forms Performance Testing PushToTest TestMaker JAT
Fantastic Tests - The Crimes of Bad Test Design
End-to-End Automated Testing: Lessons from Zombieland
Lessons Learned in Test Automation From Zombieland
Chaos Engineering - Limiting Damage During Chaos Experiments
Test Drive Development
Solving Flaky Automated Tests Using Machine Learning
SoftwareTesing_UNIT-1use it my teacher give it
The Developer’s Guide to Test Automation
Curiosity software Ireland and Perfecto present: achieving in-sprint regressi...
The Survey Says: Testers Spend Their Time Doing...
Dba tips and_tricks
DevOps in Practice: When does "Practice" Become "Doing"?
6 Easy Steps to Write Test Cases
Insoft training day_1
Clean & Dirty Acceptance Tests with Cucumber & Watir
Applying principles of chaos engineering to serverless (O'Reilly Software Arc...
Exploring Best Practises in Design of Experiments: A Data Driven Approach to ...
You have no idea what your users want - WordCamp PDX
Nevera Dul Moment
Oracle Forms Performance Testing PushToTest TestMaker JAT
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

Ten things you should know when writing good unit test cases

  • 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