SlideShare a Scribd company logo
TESTS THAT TALK 
or 
10 simple rules for cleaner, maintainable, readable tests
USEFUL RESOURCES 
• Effective Unit Testing: A guide for Java developers - Lasse Koskela 
• Clean Code & Clean Coder - Uncle Bob 
• Test Driven Development - Kent Beck 
• Specification By Example - Gojko Adzic 
• Agile Testing: A Practical Guide for Testers and Agile Teams - Lisa 
Crispin & Janet Gregory
DISTRIBUTE YOUR 
EFFORTS 
#1
Unit tests 
Component tests 
Integration tests 
Performance tests 
Acceptance Tests
#2 
TEST CODE IS AS 
IMPORTANT AS 
PRODUCTION CODE
• It should be clean & maintainable 
• it should be efficient and effective 
• its behaviour should be deterministic 
• don’t live with dead code 
• this includes ignored tests!
• Given-When-Then / Given-Expect #win 
• Name test methods like “shouldXXX” 
• Use alphabetic suffixes rather than numerical as its 
easier to read
TEST ONE THING AT 
A TIME 
#3
•Makes tracing failures easier 
•Avoid loops, use parameterisation 
• Promotes re-use of code 
• Coupled with BDD-esque style means test reports 
form detailed behavioural specifications
ENCAPSULATE DATA 
OBJECT CREATION 
#4
• Exploit builder patterns and internal DSLs for more 
human-readable test setup 
• Don’t mix test code with testing utility classes 
•Test your utility classes (reuse!)
MOCKING 
#5 
INTRODUCES FRAGILITY
• An expectation on a mock object is an implicit 
assumption that the concrete implementation 
behaves in a specific way 
• Has a tendency to introduce tight coupling 
•Try to mock only across boundaries: view-controller 
<-> service layer <-> persistence layer 
• Minimise the amount of verification on mock 
objects
DON’T REBUILD THE 
WORLD IF ALL YOU 
NEED IS TO REBUILD 
THE HOUSE 
#6
• Setting up test environments can be expensive 
• When loading data, e.g. DbUnit, try and minimise 
the dataset size 
•Typically the higher up the “test pyramid” the more 
expensive 
• If a test “dirties” the environment prefer cleaning up 
over recreating the environment 
• Isolate tests to allow parallel execution on a shared 
environment, e.g. user objects in integration tests
ASSERT IN ENGLISH* 
*(IRONY NOTED) 
#7
• JUnit’s assertThat + Hamcrest is a good start 
•Writing custom matchers is easy 
•Generics are a PITA 
•Awaitility is a DSL for working with asynchronous 
APIs 
• JodaTime API is great for date/time comparisons 
• Assertj is an extensible assertion framework more 
natural than JUnit’s
CATEGORISE YOUR 
TESTS 
#8
•Group by: 
•Speed 
• Feature set 
•Work in progress 
•Layer 
•OS/Browser 
•Provide methods to execute a collection of test 
groups as well as the full suite
#9 GO NATIVE
•Encourage non- & semi-technical participation in 
feature specification with BDD frameworks 
• JBehave 
•CucumberJVM 
•RAML 
•lambda-behave 
• Be the agent of change: Spock
HAVE FUN! 
#10
IMAGES SOURCES 
• http://free-extras.com/images/broken_heart-1503.htm 
• http://www.makergear.com/products/m-series-3d-printers 
• http://xkcd.com/435/ 
• http://justfree.org/fruit-clip-art
TESTS THAT TALK 
or 
10 simple rules for cleaner, maintainable, readable tests

More Related Content

PPTX
How to practice TDD without shooting yourself in the foot
PDF
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
PPTX
Building autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
PPTX
Building occasionally connected applications using event sourcing
PPTX
Fastly CEO Artur Bergman at Altitude NYC
PDF
HTTPS and Ansible
PPTX
Node.js Dublin Meetup April 2014
PDF
Building and Releasing a Golang CLI Tool
How to practice TDD without shooting yourself in the foot
Performance Testing w/ WebPage Test Private Instance (DrupalCamp Ohio)
Building autonomous components with OWIN, PSake, NuGet, GitVersion and Swagger
Building occasionally connected applications using event sourcing
Fastly CEO Artur Bergman at Altitude NYC
HTTPS and Ansible
Node.js Dublin Meetup April 2014
Building and Releasing a Golang CLI Tool

What's hot (20)

PDF
Make your Ansible playbooks maintainable, flexible, and scalable
PPTX
Serverless testing-serverless-sydney-20181018
PDF
Devops - why, what and how?
PDF
Creating Hyper Performant Web Apps with React
PPTX
Managing changes to eZPublish Database
PDF
Building Codealike: a journey into the developers analytics world
PPTX
Continuous database deployment
PDF
Powerful Automation Made Simple
PDF
Queue Everything and Please Everyone
PDF
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
PPTX
Automation testing of REST endpoints in a less coded way
PDF
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
PPTX
Why Wordnik went non-relational
PDF
CFWheels - Pragmatic, Beautiful Code
PPTX
Benchmarking NGINX for Accuracy and Results
PPTX
Prepare for Launch: A Pre-Launch Checklist for Life on the Web
PPT
Ops Works Presentation Desert Code Camp 2014
PPTX
Testing Below the Application
PPTX
Command box, Package Manager, Automation, REPL
PPTX
Tuenti Release Workflow
Make your Ansible playbooks maintainable, flexible, and scalable
Serverless testing-serverless-sydney-20181018
Devops - why, what and how?
Creating Hyper Performant Web Apps with React
Managing changes to eZPublish Database
Building Codealike: a journey into the developers analytics world
Continuous database deployment
Powerful Automation Made Simple
Queue Everything and Please Everyone
Altitude San Francisco 2018: HTTP/2 Tales: Discovery and Woe
Automation testing of REST endpoints in a less coded way
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Why Wordnik went non-relational
CFWheels - Pragmatic, Beautiful Code
Benchmarking NGINX for Accuracy and Results
Prepare for Launch: A Pre-Launch Checklist for Life on the Web
Ops Works Presentation Desert Code Camp 2014
Testing Below the Application
Command box, Package Manager, Automation, REPL
Tuenti Release Workflow
Ad

Similar to Tests that talk (20)

PPTX
Introduction to Testing and TDD
PPTX
Understanding TDD - theory, practice, techniques and tips.
PDF
Developers Testing - Girl Code at bloomon
PDF
Introduction to Unit Tests and TDD
PPTX
Introduction to Test Driven Development
PPTX
Test driven development v1.0
PPTX
Test Driven Development
PPTX
Level Up Your Salesforce Unit Testing
PPTX
Testing, a pragmatic approach
PPT
Pa Project And Best Practice 2
PDF
Tdd practices
PPTX
Lean-Agile Development with SharePoint - Bill Ayers
PPTX
Unit testing
PDF
PPTX
Cleaner Code Through Test-Driven Development
PPTX
Simplifying Integration Testing in a Containerized World
PPTX
MyHeritage - QA Automations in a Continuous Deployment environment
PPTX
Acceptance Test Driven Development
PDF
Test driven development - Zombie proof your code
PPTX
Unit Testing talk
Introduction to Testing and TDD
Understanding TDD - theory, practice, techniques and tips.
Developers Testing - Girl Code at bloomon
Introduction to Unit Tests and TDD
Introduction to Test Driven Development
Test driven development v1.0
Test Driven Development
Level Up Your Salesforce Unit Testing
Testing, a pragmatic approach
Pa Project And Best Practice 2
Tdd practices
Lean-Agile Development with SharePoint - Bill Ayers
Unit testing
Cleaner Code Through Test-Driven Development
Simplifying Integration Testing in a Containerized World
MyHeritage - QA Automations in a Continuous Deployment environment
Acceptance Test Driven Development
Test driven development - Zombie proof your code
Unit Testing talk
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation_ Review paper, used for researhc scholars

Tests that talk

  • 1. TESTS THAT TALK or 10 simple rules for cleaner, maintainable, readable tests
  • 2. USEFUL RESOURCES • Effective Unit Testing: A guide for Java developers - Lasse Koskela • Clean Code & Clean Coder - Uncle Bob • Test Driven Development - Kent Beck • Specification By Example - Gojko Adzic • Agile Testing: A Practical Guide for Testers and Agile Teams - Lisa Crispin & Janet Gregory
  • 4. Unit tests Component tests Integration tests Performance tests Acceptance Tests
  • 5. #2 TEST CODE IS AS IMPORTANT AS PRODUCTION CODE
  • 6. • It should be clean & maintainable • it should be efficient and effective • its behaviour should be deterministic • don’t live with dead code • this includes ignored tests!
  • 7. • Given-When-Then / Given-Expect #win • Name test methods like “shouldXXX” • Use alphabetic suffixes rather than numerical as its easier to read
  • 8. TEST ONE THING AT A TIME #3
  • 9. •Makes tracing failures easier •Avoid loops, use parameterisation • Promotes re-use of code • Coupled with BDD-esque style means test reports form detailed behavioural specifications
  • 10. ENCAPSULATE DATA OBJECT CREATION #4
  • 11. • Exploit builder patterns and internal DSLs for more human-readable test setup • Don’t mix test code with testing utility classes •Test your utility classes (reuse!)
  • 13. • An expectation on a mock object is an implicit assumption that the concrete implementation behaves in a specific way • Has a tendency to introduce tight coupling •Try to mock only across boundaries: view-controller <-> service layer <-> persistence layer • Minimise the amount of verification on mock objects
  • 14. DON’T REBUILD THE WORLD IF ALL YOU NEED IS TO REBUILD THE HOUSE #6
  • 15. • Setting up test environments can be expensive • When loading data, e.g. DbUnit, try and minimise the dataset size •Typically the higher up the “test pyramid” the more expensive • If a test “dirties” the environment prefer cleaning up over recreating the environment • Isolate tests to allow parallel execution on a shared environment, e.g. user objects in integration tests
  • 16. ASSERT IN ENGLISH* *(IRONY NOTED) #7
  • 17. • JUnit’s assertThat + Hamcrest is a good start •Writing custom matchers is easy •Generics are a PITA •Awaitility is a DSL for working with asynchronous APIs • JodaTime API is great for date/time comparisons • Assertj is an extensible assertion framework more natural than JUnit’s
  • 19. •Group by: •Speed • Feature set •Work in progress •Layer •OS/Browser •Provide methods to execute a collection of test groups as well as the full suite
  • 21. •Encourage non- & semi-technical participation in feature specification with BDD frameworks • JBehave •CucumberJVM •RAML •lambda-behave • Be the agent of change: Spock
  • 23. IMAGES SOURCES • http://free-extras.com/images/broken_heart-1503.htm • http://www.makergear.com/products/m-series-3d-printers • http://xkcd.com/435/ • http://justfree.org/fruit-clip-art
  • 24. TESTS THAT TALK or 10 simple rules for cleaner, maintainable, readable tests