SlideShare a Scribd company logo
Good Tests 
A few things on how to write good tests 
Page 1 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Summary 
Page 2 
• Motivation for testing 
• Good tests 
• Some advice to write better tests 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Manual vs automated testing 
CalculatorApp 
Enter first value: 5 
Enter second value: 10 
What operation: add 
Result is: 15 
testThatAdditionWorks() { 
firstValue = 5 
secondValue = 10 
result = calculator.add(firstValue, secondValue) 
verify(result, equals(15)) 
} 
Page 3 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Why do we write tests at all? 
https://www.flickr.com/photos/nicolopaternoster/3933549608 
Page 4 
Confidence 
- We write tests to have confidence in our software. 
- To hand the software to our customers and KNOW that it works. 
- To be able to make changes and know that it still works. 
Everybody knows that: 
„I‘m not sure, if I change this, will something break?“ 
If the tests are good, you can change your code with confidence. 
Because the tests will tell you, if you changed the behaviour! 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
When do I have enough (unit)tests? 
Experiment: Delete the contents of a class and recreate the code 
only from the tests. 
Page 5 
How many tests should I write? 
How many assertions? 
How much coverage is enough? 
When can I stop writing tests? When am I done? 
Write tests first. 
Only write code, when tests are red. 
And automatically you have enough tests, assertions and coverage. 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
What makes a test a good one? 
It‘s not easy to write good tests. 
There are a lot of requirements to our tests: 
• Should be easy to read and understand. 
• Should communicate intent well. 
• Should be easy to maintain. 
• Should provide a clear message, when they fail. 
• Should test only one feature 
• Should execute fast 
• Should be complete 
And very important: 
• We write a lot of tests. There is more test code than production code. 
https://www.flickr.com/photos/83633410@N07/7658298768 
Page 6 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
And what happens instead? 
• Tests are hard to maintain 
• Tests are hard to understand 
• Tests break often 
All the above are signs of bad tests. 
Page 7 
-> The tests become a burden 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
https://www.flickr.com/photos/spackletoe/90811910/sizes/l 
Page 8 
Solution is simple: Write good tests! 
But: 
What makes a test a good test? 
How to write good tests? 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Tests as requirements 
Requirements describe an event / action and the expected result: 
• When request A is send, module X shall respond with B. 
• A click on the x-button shall close the window. 
• Input values of 2 and 4 shall result in a return value of 6. 
Page 9 
Don‘t: 
test() 
testMethodName() 
Do: 
test_that_click_on_x-button_closes_window() 
test_that_2_and_4_return_6() 
should_throw_exception_on_empty_username() 
→ communicates intent very well 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Tests as documentation 
Page 10 
• Good tests help to understand the application 
• Documents the behaviour of the application 
• Not outdated like requirements or documentation 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Refactor tests 
Remove noise and duplication at test setup / „given phase“. 
Many tests have the same setup, only subtle differences in the test data. 
Page 11 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Object Mother 
• Factory for test data 
• Has (static) methods to create test objects 
• Creates standard fixtures (certain state/baseline) for tests 
Examples: 
• Address address = TestAddress.newAddressInGermany(); 
• Customer customer = TestCustomer.newCustomer(); 
Problems: 
• With variability in test data many methods are created 
• Tend to become “God-classes”, messy and hard to maintain 
Page 13 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Test Data Builders 
• Based on builder pattern 
• Comes with defaults for all fields 
• Tests that don‘t care about certain values, use defaults 
• Tests that need certain values, override only those 
• Thus the relevant parts are outlined 
Example: 
• Address address = new AddressBuilder().withStreet(“Andreasstr.”).build(); 
• Customer customer = new CustomerBuilder().build(); 
Page 14 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
How to write a builder 
Page 15 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Or use 
For Java: make-it-easy 
Makes it easier to create test data builders 
https://code.google.com/p/make-it-easy/ 
Page 16 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Conclusion 
Page 19 
• Try to write good tests, a lot of bad tests are really painful 
• Specify the behaviour of your software with tests 
• Write tests as requirements to communicate intent 
• Write tests before the implementation code for best coverage 
• Refactor tests, especially extract methods 
• Improve your tests with Object Mothers or Test Data Builders 
| Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
Questions?

More Related Content

What's hot

UI Automation Quirks
UI Automation QuirksUI Automation Quirks
UI Automation Quirks
Lucas Pang
 
Developer Night - Opticon18
Developer Night - Opticon18Developer Night - Opticon18
Developer Night - Opticon18
Optimizely
 
Humans by the hundred
Humans by the hundredHumans by the hundred
Humans by the hundred
Yelp Engineering
 
How to scale your Test Automation
How to scale your Test AutomationHow to scale your Test Automation
How to scale your Test Automation
Klaus Salchner
 
iOS Testing With Appium at Gilt
iOS Testing With Appium at GiltiOS Testing With Appium at Gilt
iOS Testing With Appium at Gilt
Gilt Tech Talks
 
Handling Changes to Your Server-Side Data Model
Handling Changes to Your Server-Side Data ModelHandling Changes to Your Server-Side Data Model
Handling Changes to Your Server-Side Data Model
Gilt Tech Talks
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Codemotion
 
Mobile Testing at Gilt
Mobile Testing at GiltMobile Testing at Gilt
Mobile Testing at Gilt
Gilt Tech Talks
 
Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsQA or the Highway
 
Balance Demand Against Throughput: Kanban Recipe for Success Step 4
Balance Demand Against Throughput: Kanban Recipe for Success Step 4Balance Demand Against Throughput: Kanban Recipe for Success Step 4
Balance Demand Against Throughput: Kanban Recipe for Success Step 4
Jason Yip
 
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
Reaching for Your Quality Stretch Goals: Testing at Realtor.comReaching for Your Quality Stretch Goals: Testing at Realtor.com
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
Klaus Salchner
 
The limits of unit testing by Craig Stuntz
The limits of unit testing by Craig StuntzThe limits of unit testing by Craig Stuntz
The limits of unit testing by Craig Stuntz
QA or the Highway
 
Agile Testing - Testing From Day 1
Agile Testing - Testing From Day 1Agile Testing - Testing From Day 1
Agile Testing - Testing From Day 1
Fadi Stephan
 
Focus on Quality: Kanban Recipe for Success Step One
Focus on Quality: Kanban Recipe for Success Step OneFocus on Quality: Kanban Recipe for Success Step One
Focus on Quality: Kanban Recipe for Success Step One
Jason Yip
 
15 cases of testing with data & psychology #CRO
15 cases of testing with data & psychology #CRO15 cases of testing with data & psychology #CRO
15 cases of testing with data & psychology #CRO
Online Dialogue
 
Writing Maintainable Tests
Writing Maintainable TestsWriting Maintainable Tests
Writing Maintainable Tests
VodqaBLR
 
Executable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and SeleniumExecutable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and Selenium
Dawn Code
 
Shifting is more than shifting left
Shifting is more than shifting leftShifting is more than shifting left
Shifting is more than shifting left
PractiTest
 
Adaptive Automation: Tests that Recover Instead of Failing
Adaptive Automation: Tests that Recover Instead of FailingAdaptive Automation: Tests that Recover Instead of Failing
Adaptive Automation: Tests that Recover Instead of Failing
TechWell
 
Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1
Fadi Stephan
 

What's hot (20)

UI Automation Quirks
UI Automation QuirksUI Automation Quirks
UI Automation Quirks
 
Developer Night - Opticon18
Developer Night - Opticon18Developer Night - Opticon18
Developer Night - Opticon18
 
Humans by the hundred
Humans by the hundredHumans by the hundred
Humans by the hundred
 
How to scale your Test Automation
How to scale your Test AutomationHow to scale your Test Automation
How to scale your Test Automation
 
iOS Testing With Appium at Gilt
iOS Testing With Appium at GiltiOS Testing With Appium at Gilt
iOS Testing With Appium at Gilt
 
Handling Changes to Your Server-Side Data Model
Handling Changes to Your Server-Side Data ModelHandling Changes to Your Server-Side Data Model
Handling Changes to Your Server-Side Data Model
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
Mobile Testing at Gilt
Mobile Testing at GiltMobile Testing at Gilt
Mobile Testing at Gilt
 
Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applications
 
Balance Demand Against Throughput: Kanban Recipe for Success Step 4
Balance Demand Against Throughput: Kanban Recipe for Success Step 4Balance Demand Against Throughput: Kanban Recipe for Success Step 4
Balance Demand Against Throughput: Kanban Recipe for Success Step 4
 
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
Reaching for Your Quality Stretch Goals: Testing at Realtor.comReaching for Your Quality Stretch Goals: Testing at Realtor.com
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
 
The limits of unit testing by Craig Stuntz
The limits of unit testing by Craig StuntzThe limits of unit testing by Craig Stuntz
The limits of unit testing by Craig Stuntz
 
Agile Testing - Testing From Day 1
Agile Testing - Testing From Day 1Agile Testing - Testing From Day 1
Agile Testing - Testing From Day 1
 
Focus on Quality: Kanban Recipe for Success Step One
Focus on Quality: Kanban Recipe for Success Step OneFocus on Quality: Kanban Recipe for Success Step One
Focus on Quality: Kanban Recipe for Success Step One
 
15 cases of testing with data & psychology #CRO
15 cases of testing with data & psychology #CRO15 cases of testing with data & psychology #CRO
15 cases of testing with data & psychology #CRO
 
Writing Maintainable Tests
Writing Maintainable TestsWriting Maintainable Tests
Writing Maintainable Tests
 
Executable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and SeleniumExecutable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and Selenium
 
Shifting is more than shifting left
Shifting is more than shifting leftShifting is more than shifting left
Shifting is more than shifting left
 
Adaptive Automation: Tests that Recover Instead of Failing
Adaptive Automation: Tests that Recover Instead of FailingAdaptive Automation: Tests that Recover Instead of Failing
Adaptive Automation: Tests that Recover Instead of Failing
 
Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1
 

Viewers also liked

Jimmy spends his day
Jimmy spends his dayJimmy spends his day
Jimmy spends his day
slouma20022
 
Flexovit industrial catalogue in russian(2)
Flexovit industrial catalogue in russian(2)Flexovit industrial catalogue in russian(2)
Flexovit industrial catalogue in russian(2)
azovinstrument
 
2016-2017 MRE Student Information Summary - Undergraduate Porfolios
2016-2017 MRE Student Information Summary - Undergraduate Porfolios2016-2017 MRE Student Information Summary - Undergraduate Porfolios
2016-2017 MRE Student Information Summary - Undergraduate PorfoliosMichael Forsyth
 
Ay nik shopping
Ay nik shoppingAy nik shopping
Ay nik shopping
Jo Sharp
 
Funny root signs
Funny root signsFunny root signs
Funny root signs
slouma20022
 
Cohort 2 Schools Orientation to Next Steps NH
Cohort 2 Schools Orientation to Next Steps NHCohort 2 Schools Orientation to Next Steps NH
Cohort 2 Schools Orientation to Next Steps NH
zwonkin
 
Goodtests
GoodtestsGoodtests
Goodtests
fxsperling
 
2013 felo catalog_en
2013 felo catalog_en2013 felo catalog_en
2013 felo catalog_en
azovinstrument
 
Presentation1 sabena
Presentation1   sabenaPresentation1   sabena
Presentation1 sabena
Shivangini Bhaskar
 
Flexovit борфрези
Flexovit борфрезиFlexovit борфрези
Flexovit борфрези
azovinstrument
 
Bessey общий каталог 2013_2014_ru_o_pr
Bessey общий каталог 2013_2014_ru_o_prBessey общий каталог 2013_2014_ru_o_pr
Bessey общий каталог 2013_2014_ru_o_pr
azovinstrument
 

Viewers also liked (12)

Jimmy spends his day
Jimmy spends his dayJimmy spends his day
Jimmy spends his day
 
Flexovit industrial catalogue in russian(2)
Flexovit industrial catalogue in russian(2)Flexovit industrial catalogue in russian(2)
Flexovit industrial catalogue in russian(2)
 
2016-2017 MRE Student Information Summary - Undergraduate Porfolios
2016-2017 MRE Student Information Summary - Undergraduate Porfolios2016-2017 MRE Student Information Summary - Undergraduate Porfolios
2016-2017 MRE Student Information Summary - Undergraduate Porfolios
 
Ay nik shopping
Ay nik shoppingAy nik shopping
Ay nik shopping
 
Funny root signs
Funny root signsFunny root signs
Funny root signs
 
Cohort 2 Schools Orientation to Next Steps NH
Cohort 2 Schools Orientation to Next Steps NHCohort 2 Schools Orientation to Next Steps NH
Cohort 2 Schools Orientation to Next Steps NH
 
Goodtests
GoodtestsGoodtests
Goodtests
 
2013 felo catalog_en
2013 felo catalog_en2013 felo catalog_en
2013 felo catalog_en
 
Co-Op Summary Revised
Co-Op Summary RevisedCo-Op Summary Revised
Co-Op Summary Revised
 
Presentation1 sabena
Presentation1   sabenaPresentation1   sabena
Presentation1 sabena
 
Flexovit борфрези
Flexovit борфрезиFlexovit борфрези
Flexovit борфрези
 
Bessey общий каталог 2013_2014_ru_o_pr
Bessey общий каталог 2013_2014_ru_o_prBessey общий каталог 2013_2014_ru_o_pr
Bessey общий каталог 2013_2014_ru_o_pr
 

Similar to Goodtests

Master the Essentials of Conversion Optimization
Master the Essentials of Conversion Optimization Master the Essentials of Conversion Optimization
Master the Essentials of Conversion Optimization
Kyle Curnow
 
Approval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience ReportApproval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience Report
houseofyin
 
Lean Startup 301
Lean Startup 301Lean Startup 301
Lean Startup 301
Lean Startup Co.
 
Acte 2015 certification magic
Acte 2015   certification magicActe 2015   certification magic
Acte 2015 certification magic
Mike Ploor
 
5 Steps to Detecting Issues Earlier in Your Release Cycles
 5 Steps to Detecting Issues Earlier in Your Release Cycles 5 Steps to Detecting Issues Earlier in Your Release Cycles
5 Steps to Detecting Issues Earlier in Your Release Cycles
Perfecto by Perforce
 
Four schools of testing context driven school
Four schools of testing   context driven schoolFour schools of testing   context driven school
Four schools of testing context driven school
Holasz Kati
 
Engl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_testEngl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_test
Zachary Williamson
 
Acte 2015 gw certification classroom solutions
Acte 2015   gw certification classroom solutionsActe 2015   gw certification classroom solutions
Acte 2015 gw certification classroom solutions
Mike Ploor
 
Continuous business goal validation
Continuous business goal validationContinuous business goal validation
Continuous business goal validation
Hylke Stapersma
 
Use Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual TestingUse Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual Testing
TechWell
 
Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)
Lars-Erik Kindblad
 
Take Your Marketing Back to School: The Science of Email Testing (slides)
Take Your Marketing Back to School: The Science of Email Testing (slides)Take Your Marketing Back to School: The Science of Email Testing (slides)
Take Your Marketing Back to School: The Science of Email Testing (slides)
WhatCounts, Inc.
 
Think Tank Presentation 5-2012
Think Tank Presentation 5-2012Think Tank Presentation 5-2012
Think Tank Presentation 5-2012
Jim Borzilleri
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
FalafelSoftware
 
Automated Testing with Logic Apps and Specflow
Automated Testing with Logic Apps and SpecflowAutomated Testing with Logic Apps and Specflow
Automated Testing with Logic Apps and Specflow
BizTalk360
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
Amir Assad
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Dinis Cruz
 
Test case writing
Test case writingTest case writing
Test case writing
Afsarah Jahin
 
Test automation engineer
Test automation engineerTest automation engineer
Test automation engineer
Sadaaki Emura
 

Similar to Goodtests (20)

Master the Essentials of Conversion Optimization
Master the Essentials of Conversion Optimization Master the Essentials of Conversion Optimization
Master the Essentials of Conversion Optimization
 
Approval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience ReportApproval Tests in Action: A LEGO Exercise and an Experience Report
Approval Tests in Action: A LEGO Exercise and an Experience Report
 
Lean Startup 301
Lean Startup 301Lean Startup 301
Lean Startup 301
 
Acte 2015 certification magic
Acte 2015   certification magicActe 2015   certification magic
Acte 2015 certification magic
 
5 Steps to Detecting Issues Earlier in Your Release Cycles
 5 Steps to Detecting Issues Earlier in Your Release Cycles 5 Steps to Detecting Issues Earlier in Your Release Cycles
5 Steps to Detecting Issues Earlier in Your Release Cycles
 
Four schools of testing context driven school
Four schools of testing   context driven schoolFour schools of testing   context driven school
Four schools of testing context driven school
 
Engl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_testEngl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_test
 
Acte 2015 gw certification classroom solutions
Acte 2015   gw certification classroom solutionsActe 2015   gw certification classroom solutions
Acte 2015 gw certification classroom solutions
 
Continuous business goal validation
Continuous business goal validationContinuous business goal validation
Continuous business goal validation
 
Use Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual TestingUse Automation to Assist—Not Replace—Manual Testing
Use Automation to Assist—Not Replace—Manual Testing
 
Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)Unit Tests are Overrated (NDCOslo 2013)
Unit Tests are Overrated (NDCOslo 2013)
 
Reliable acceptance testing
Reliable acceptance testingReliable acceptance testing
Reliable acceptance testing
 
Take Your Marketing Back to School: The Science of Email Testing (slides)
Take Your Marketing Back to School: The Science of Email Testing (slides)Take Your Marketing Back to School: The Science of Email Testing (slides)
Take Your Marketing Back to School: The Science of Email Testing (slides)
 
Think Tank Presentation 5-2012
Think Tank Presentation 5-2012Think Tank Presentation 5-2012
Think Tank Presentation 5-2012
 
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
 
Automated Testing with Logic Apps and Specflow
Automated Testing with Logic Apps and SpecflowAutomated Testing with Logic Apps and Specflow
Automated Testing with Logic Apps and Specflow
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)
 
Test case writing
Test case writingTest case writing
Test case writing
 
Test automation engineer
Test automation engineerTest automation engineer
Test automation engineer
 

Recently uploaded

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
nikitacareer3
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 

Recently uploaded (20)

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 

Goodtests

  • 1. Good Tests A few things on how to write good tests Page 1 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 2. Summary Page 2 • Motivation for testing • Good tests • Some advice to write better tests | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 3. Manual vs automated testing CalculatorApp Enter first value: 5 Enter second value: 10 What operation: add Result is: 15 testThatAdditionWorks() { firstValue = 5 secondValue = 10 result = calculator.add(firstValue, secondValue) verify(result, equals(15)) } Page 3 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 4. Why do we write tests at all? https://www.flickr.com/photos/nicolopaternoster/3933549608 Page 4 Confidence - We write tests to have confidence in our software. - To hand the software to our customers and KNOW that it works. - To be able to make changes and know that it still works. Everybody knows that: „I‘m not sure, if I change this, will something break?“ If the tests are good, you can change your code with confidence. Because the tests will tell you, if you changed the behaviour! | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 5. When do I have enough (unit)tests? Experiment: Delete the contents of a class and recreate the code only from the tests. Page 5 How many tests should I write? How many assertions? How much coverage is enough? When can I stop writing tests? When am I done? Write tests first. Only write code, when tests are red. And automatically you have enough tests, assertions and coverage. | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 6. What makes a test a good one? It‘s not easy to write good tests. There are a lot of requirements to our tests: • Should be easy to read and understand. • Should communicate intent well. • Should be easy to maintain. • Should provide a clear message, when they fail. • Should test only one feature • Should execute fast • Should be complete And very important: • We write a lot of tests. There is more test code than production code. https://www.flickr.com/photos/83633410@N07/7658298768 Page 6 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 7. And what happens instead? • Tests are hard to maintain • Tests are hard to understand • Tests break often All the above are signs of bad tests. Page 7 -> The tests become a burden | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 8. https://www.flickr.com/photos/spackletoe/90811910/sizes/l Page 8 Solution is simple: Write good tests! But: What makes a test a good test? How to write good tests? | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 9. Tests as requirements Requirements describe an event / action and the expected result: • When request A is send, module X shall respond with B. • A click on the x-button shall close the window. • Input values of 2 and 4 shall result in a return value of 6. Page 9 Don‘t: test() testMethodName() Do: test_that_click_on_x-button_closes_window() test_that_2_and_4_return_6() should_throw_exception_on_empty_username() → communicates intent very well | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 10. Tests as documentation Page 10 • Good tests help to understand the application • Documents the behaviour of the application • Not outdated like requirements or documentation | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 11. Refactor tests Remove noise and duplication at test setup / „given phase“. Many tests have the same setup, only subtle differences in the test data. Page 11 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 12. Object Mother • Factory for test data • Has (static) methods to create test objects • Creates standard fixtures (certain state/baseline) for tests Examples: • Address address = TestAddress.newAddressInGermany(); • Customer customer = TestCustomer.newCustomer(); Problems: • With variability in test data many methods are created • Tend to become “God-classes”, messy and hard to maintain Page 13 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 13. Test Data Builders • Based on builder pattern • Comes with defaults for all fields • Tests that don‘t care about certain values, use defaults • Tests that need certain values, override only those • Thus the relevant parts are outlined Example: • Address address = new AddressBuilder().withStreet(“Andreasstr.”).build(); • Customer customer = new CustomerBuilder().build(); Page 14 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 14. How to write a builder Page 15 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 15. Or use For Java: make-it-easy Makes it easier to create test data builders https://code.google.com/p/make-it-easy/ Page 16 | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014
  • 16. Conclusion Page 19 • Try to write good tests, a lot of bad tests are really painful • Specify the behaviour of your software with tests • Write tests as requirements to communicate intent • Write tests before the implementation code for best coverage • Refactor tests, especially extract methods • Improve your tests with Object Mothers or Test Data Builders | Good Tests | Felix Sperling | Twitter: @felixsperling | 09.10.2014