SlideShare uma empresa Scribd logo
1 de 29
Unit Testing Patterns
or
How a talk looks like when you
take it over one day before giving it
We are the Code Retreat Brothers
@alexboly @adibolb
First European Code Retreat,
co-facilitated with Maria
Many Code Retreats around Europe
Disclaimers
1.Nobody was hurt while creating the talk
2.It's the fastest talk we ever created
3.It answers your questions
4.We might be wrong
5.It might contain jokes and 5-level pyramids
The top 5 things I'd like to do in the next
hour
Talk, talk, talk
Discuss, answer questions
Practice
Rescue legacy
code or tests
Learn He told me I
could draw
So, unit testing patterns. What do you
want to learn?
Here's what we'll answer
1. What to unit test?
2. How to organize tests?
3. How to deal with complex test setups?
4. How to avoid brittle tests?
5. How to integrate devs & testers in the team?
6. How and when to introduce tests on legacy code?
7. How to do Javascript unit testing?
8. How to unit test databases?
But before that, some background
● Pyramid of tests
● Behavior Slicing
● Unit Test Structure
● Stubs vs. Mocks
Pyramid of Tests
How you should do testing
Unit Tests
Integration tests
Component tests
System
tests
...
That's the 5 level pyramid
estimation error
How you really do testing
Unit Tests
Integration tests
Component tests
System
tests
...
UnitTests
Integrationtests
Componenttests
System
tests
...
Behavior Slicing
How many tests should you write for this
code?
public int sameNumber(int number){
return number;
}
How many tests should you write for this
code?
public int sum(int first, int second){
return first + second;
}
How many tests should you write for this
code?
public DateTime daysAfter(DateTime date, int
days){
...
}
Behavior Slicing
● The process to identify behaviors that the code
should do
● How:
– Identify input and output
– Choose the important values for input (value sampling
or equivalence partitioning)
● Write one unit test per behavior
Property based testing
@forall(x=[1,2], y=[20,30])
def test_can_specify_fixed_sequence_of_inputs(x, y):
assert x in (1,2) and y in (20,30)
Stubs vs. Mocks
(Alex needs to say two jokes)
Stubs vs. Mocks
Both are test doubles, but:
● Stubs return values
● Mocks check method calls
What to test?
Risk-based testing
● What is the feature that, if it doesn't work, you
loose money?
● What is the part of the code that, if it doesn't
work, will bring the system down?
● What is the most complex part of the software?
● What are the types of mistakes the team makes
when developing?
How to organize tests?
● Will not show the 5-level
pyramid again
How to deal with complex test setups?
● One behavior per test
● Object Mother
– creates examples for tests
– e.g., the 'John' employee
● Builder pattern:
– aDate.withDay(1).withYear(2013).build();
● Maybe your production code design needs improvement
How to avoid brittle tests?
● One behavior per test (focus on behavior)
● Adjust level of checks
● Short tests
How to integrate devs and testers?
● Cross functional teams
● Pair tester and programmer on stories
● Maybe: Developer in Test role
– Watch Aimee Rivers' talk on
http://2013.itakeunconf.com
How and when to introduce tests on legacy
code?
● On modules with high cost of failure
● Whenever changing the code
– fixing a bug
– adding a feature
– code improvements
● If the code doesn't need to change, don't test it
● Start from integration tests and go down the pyramid
Javascript unit testing
● Watch James Shore testing Javascript at
http://vimeo.com/68334907
Testing Databases
● Stored procedures, functions => DbUnit
● Access, check ORM works, queries are
correct => Integration tests
● Performance, scalability etc. => tools
Any other questions?
“The important thing is to never
stop questioning”
Thank You!
@alexboly
@adibolb

Mais conteúdo relacionado

Mais procurados

Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests EffectivelyPaul Boocock
 
Los diez mandamientos de TDD
Los diez mandamientos de TDDLos diez mandamientos de TDD
Los diez mandamientos de TDDHernan Wilkinson
 
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile Projects
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile ProjectsAgile Testing Days 2014 Keynote - Helping Testers Add Value on Agile Projects
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile ProjectsAlan Richardson
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPECWojciech Bulaty
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
There is NO test automation
There is NO test automationThere is NO test automation
There is NO test automationEddy Bruin
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit TestingEyal Kenig
 
Legis pactum building high performance teams
Legis pactum   building high performance teamsLegis pactum   building high performance teams
Legis pactum building high performance teamsMiguel Pinto
 
Worst practices in software testing by the Testing troll
Worst practices in software testing by the Testing trollWorst practices in software testing by the Testing troll
Worst practices in software testing by the Testing trollViktor Slavchev
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testingDharmendra Prasad
 
Testing & should i do it
Testing & should i do itTesting & should i do it
Testing & should i do itMartin Sykora
 
Kata experience experimentation form to print on a3
Kata experience experimentation form to print on a3Kata experience experimentation form to print on a3
Kata experience experimentation form to print on a3Håkan Forss
 
Obejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCMObejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCMHernan Wilkinson
 
Microsoft 98-388 Exam Dumps Questions
Microsoft 98-388 Exam Dumps QuestionsMicrosoft 98-388 Exam Dumps Questions
Microsoft 98-388 Exam Dumps QuestionsBraindumps4IT
 

Mais procurados (20)

Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests Effectively
 
Los diez mandamientos de TDD
Los diez mandamientos de TDDLos diez mandamientos de TDD
Los diez mandamientos de TDD
 
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile Projects
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile ProjectsAgile Testing Days 2014 Keynote - Helping Testers Add Value on Agile Projects
Agile Testing Days 2014 Keynote - Helping Testers Add Value on Agile Projects
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Assorted TDD tips
Assorted TDD tipsAssorted TDD tips
Assorted TDD tips
 
There is NO test automation
There is NO test automationThere is NO test automation
There is NO test automation
 
TDD talk
TDD talkTDD talk
TDD talk
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
Legis pactum building high performance teams
Legis pactum   building high performance teamsLegis pactum   building high performance teams
Legis pactum building high performance teams
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Worst practices in software testing by the Testing troll
Worst practices in software testing by the Testing trollWorst practices in software testing by the Testing troll
Worst practices in software testing by the Testing troll
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
 
Testing & should i do it
Testing & should i do itTesting & should i do it
Testing & should i do it
 
Kata experience experimentation form to print on a3
Kata experience experimentation form to print on a3Kata experience experimentation form to print on a3
Kata experience experimentation form to print on a3
 
Obejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCMObejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCM
 
Microsoft 98-388 Exam Dumps Questions
Microsoft 98-388 Exam Dumps QuestionsMicrosoft 98-388 Exam Dumps Questions
Microsoft 98-388 Exam Dumps Questions
 

Destaque

The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)Radu Marinescu
 
Simplifying your design with higher-order functions
Simplifying your design with higher-order functionsSimplifying your design with higher-order functions
Simplifying your design with higher-order functionsSamir Talwar
 
I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"Cyrille Martraire
 
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Mozaic Works
 
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestSandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestMozaic Works
 
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Mozaic Works
 

Destaque (6)

The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
The Good the Bad and the Ugly of Dealing with Smelly Code (ITAKE Unconference)
 
Simplifying your design with higher-order functions
Simplifying your design with higher-order functionsSimplifying your design with higher-order functions
Simplifying your design with higher-order functions
 
I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"I T.A.K.E. talk: "When DDD meets FP, good things happen"
I T.A.K.E. talk: "When DDD meets FP, good things happen"
 
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
Erik talboom - TDD as if The Baby Meant it @I T.A.K.E. Unconference 2013, Buc...
 
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, BucharestSandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
Sandro Mancuso - Software Craftmanship @ I T.A.K.E. Unconference 2013, Bucharest
 
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
Sandro Mancuso – Testing and refactoring legacy code @ I T.A.K.E. Unconferenc...
 

Semelhante a Unit testing-patterns

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentjakubkoci
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support developmentChema del Barco
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
debugging.ppt
debugging.pptdebugging.ppt
debugging.pptjerlinS1
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
When develpment met test(shift left testing)
When develpment met test(shift left testing)When develpment met test(shift left testing)
When develpment met test(shift left testing)SangIn Choung
 
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
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
Open source bridge testing antipatterns presentation
Open source bridge testing antipatterns presentationOpen source bridge testing antipatterns presentation
Open source bridge testing antipatterns presentationmmrobins
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development Amir Assad
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
How Good of a Java Developer are You?
How Good of a Java Developer are You?How Good of a Java Developer are You?
How Good of a Java Developer are You?Sherif Koussa
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 

Semelhante a Unit testing-patterns (20)

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support development
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
debugging.ppt
debugging.pptdebugging.ppt
debugging.ppt
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
When develpment met test(shift left testing)
When develpment met test(shift left testing)When develpment met test(shift left testing)
When develpment met test(shift left testing)
 
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
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Open source bridge testing antipatterns presentation
Open source bridge testing antipatterns presentationOpen source bridge testing antipatterns presentation
Open source bridge testing antipatterns presentation
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
How Good of a Java Developer are You?
How Good of a Java Developer are You?How Good of a Java Developer are You?
How Good of a Java Developer are You?
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 

Mais de Alexandru Bolboaca (20)

Refactor legacy code through pure functions
Refactor legacy code through pure functionsRefactor legacy code through pure functions
Refactor legacy code through pure functions
 
Design Without Types
Design Without TypesDesign Without Types
Design Without Types
 
Thinking in Functions
Thinking in FunctionsThinking in Functions
Thinking in Functions
 
Raising the Bar
Raising the BarRaising the Bar
Raising the Bar
 
The Journey to Master Code Design
The Journey to Master Code DesignThe Journey to Master Code Design
The Journey to Master Code Design
 
What is good software design? And why it matters?
What is good software design? And why it matters?What is good software design? And why it matters?
What is good software design? And why it matters?
 
Functional programming in C++
Functional programming in C++Functional programming in C++
Functional programming in C++
 
Agile Technical Leadership
Agile Technical LeadershipAgile Technical Leadership
Agile Technical Leadership
 
TDD As If You Meant It
TDD As If You Meant ItTDD As If You Meant It
TDD As If You Meant It
 
Usable Software Design
Usable Software DesignUsable Software Design
Usable Software Design
 
Hidden loops
Hidden loopsHidden loops
Hidden loops
 
Removing structural duplication
Removing structural duplicationRemoving structural duplication
Removing structural duplication
 
Continuous delivery
Continuous deliveryContinuous delivery
Continuous delivery
 
Why You Should Start Using Docker
Why You Should Start Using DockerWhy You Should Start Using Docker
Why You Should Start Using Docker
 
Pyramid of-developer-skills
Pyramid of-developer-skillsPyramid of-developer-skills
Pyramid of-developer-skills
 
Applied craftsmanship
Applied craftsmanshipApplied craftsmanship
Applied craftsmanship
 
Pyramid of-developer-skills
Pyramid of-developer-skillsPyramid of-developer-skills
Pyramid of-developer-skills
 
Stay focused
Stay focusedStay focused
Stay focused
 
Kanban intro
Kanban introKanban intro
Kanban intro
 
Incremental design, simply explained
Incremental design, simply explainedIncremental design, simply explained
Incremental design, simply explained
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Unit testing-patterns

  • 1. Unit Testing Patterns or How a talk looks like when you take it over one day before giving it
  • 2. We are the Code Retreat Brothers @alexboly @adibolb First European Code Retreat, co-facilitated with Maria Many Code Retreats around Europe
  • 3. Disclaimers 1.Nobody was hurt while creating the talk 2.It's the fastest talk we ever created 3.It answers your questions 4.We might be wrong 5.It might contain jokes and 5-level pyramids
  • 4. The top 5 things I'd like to do in the next hour Talk, talk, talk Discuss, answer questions Practice Rescue legacy code or tests Learn He told me I could draw
  • 5. So, unit testing patterns. What do you want to learn?
  • 6. Here's what we'll answer 1. What to unit test? 2. How to organize tests? 3. How to deal with complex test setups? 4. How to avoid brittle tests? 5. How to integrate devs & testers in the team? 6. How and when to introduce tests on legacy code? 7. How to do Javascript unit testing? 8. How to unit test databases?
  • 7. But before that, some background ● Pyramid of tests ● Behavior Slicing ● Unit Test Structure ● Stubs vs. Mocks
  • 9. How you should do testing Unit Tests Integration tests Component tests System tests ... That's the 5 level pyramid estimation error
  • 10. How you really do testing Unit Tests Integration tests Component tests System tests ... UnitTests Integrationtests Componenttests System tests ...
  • 12. How many tests should you write for this code? public int sameNumber(int number){ return number; }
  • 13. How many tests should you write for this code? public int sum(int first, int second){ return first + second; }
  • 14. How many tests should you write for this code? public DateTime daysAfter(DateTime date, int days){ ... }
  • 15. Behavior Slicing ● The process to identify behaviors that the code should do ● How: – Identify input and output – Choose the important values for input (value sampling or equivalence partitioning) ● Write one unit test per behavior
  • 16. Property based testing @forall(x=[1,2], y=[20,30]) def test_can_specify_fixed_sequence_of_inputs(x, y): assert x in (1,2) and y in (20,30)
  • 17. Stubs vs. Mocks (Alex needs to say two jokes)
  • 18. Stubs vs. Mocks Both are test doubles, but: ● Stubs return values ● Mocks check method calls
  • 20. Risk-based testing ● What is the feature that, if it doesn't work, you loose money? ● What is the part of the code that, if it doesn't work, will bring the system down? ● What is the most complex part of the software? ● What are the types of mistakes the team makes when developing?
  • 21. How to organize tests? ● Will not show the 5-level pyramid again
  • 22. How to deal with complex test setups? ● One behavior per test ● Object Mother – creates examples for tests – e.g., the 'John' employee ● Builder pattern: – aDate.withDay(1).withYear(2013).build(); ● Maybe your production code design needs improvement
  • 23. How to avoid brittle tests? ● One behavior per test (focus on behavior) ● Adjust level of checks ● Short tests
  • 24. How to integrate devs and testers? ● Cross functional teams ● Pair tester and programmer on stories ● Maybe: Developer in Test role – Watch Aimee Rivers' talk on http://2013.itakeunconf.com
  • 25. How and when to introduce tests on legacy code? ● On modules with high cost of failure ● Whenever changing the code – fixing a bug – adding a feature – code improvements ● If the code doesn't need to change, don't test it ● Start from integration tests and go down the pyramid
  • 26. Javascript unit testing ● Watch James Shore testing Javascript at http://vimeo.com/68334907
  • 27. Testing Databases ● Stored procedures, functions => DbUnit ● Access, check ORM works, queries are correct => Integration tests ● Performance, scalability etc. => tools
  • 28. Any other questions? “The important thing is to never stop questioning”