SlideShare a Scribd company logo
1 of 17
Download to read offline
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 QuirksLucas Pang
 
Developer Night - Opticon18
Developer Night - Opticon18Developer Night - Opticon18
Developer Night - Opticon18Optimizely
 
How to scale your Test Automation
How to scale your Test AutomationHow to scale your Test Automation
How to scale your Test AutomationKlaus Salchner
 
iOS Testing With Appium at Gilt
iOS Testing With Appium at GiltiOS Testing With Appium at Gilt
iOS Testing With Appium at GiltGilt 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 ModelGilt 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 2019Codemotion
 
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 4Jason 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.comKlaus 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 StuntzQA 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 1Fadi 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 OneJason 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 #CROOnline Dialogue
 
Writing Maintainable Tests
Writing Maintainable TestsWriting Maintainable Tests
Writing Maintainable TestsVodqaBLR
 
Executable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and SeleniumExecutable Specifications with FitNesse and Selenium
Executable Specifications with FitNesse and SeleniumDawn Code
 
Shifting is more than shifting left
Shifting is more than shifting leftShifting is more than shifting left
Shifting is more than shifting leftPractiTest
 
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 FailingTechWell
 
Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1Agile Testing - Testing from Day 1
Agile Testing - Testing from Day 1Fadi 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 dayslouma20022
 
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 shoppingJo Sharp
 
Funny root signs
Funny root signsFunny root signs
Funny root signsslouma20022
 
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 NHzwonkin
 
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_prazovinstrument
 

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 Reporthouseofyin
 
Acte 2015 certification magic
Acte 2015   certification magicActe 2015   certification magic
Acte 2015 certification magicMike 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 CyclesPerfecto 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 schoolHolasz Kati
 
Engl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_testEngl317 project4 slidedoc2_stepsto_designux_test
Engl317 project4 slidedoc2_stepsto_designux_testZachary Williamson
 
Acte 2015 gw certification classroom solutions
Acte 2015   gw certification classroom solutionsActe 2015   gw certification classroom solutions
Acte 2015 gw certification classroom solutionsMike Ploor
 
Continuous business goal validation
Continuous business goal validationContinuous business goal validation
Continuous business goal validationHylke 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 TestingTechWell
 
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-2012Jim 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 SpecflowBizTalk360
 
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 automation engineer
Test automation engineerTest automation engineer
Test automation engineerSadaaki 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

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

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