SlideShare a Scribd company logo
Bigger Unit Test Are Better
why having many small unit test classes will slow you down
%: whoami
• Peter Schuler
• Java developer @ Rabobank @ Tribe Wonen
• Trainer and coach
• Writing code since 1992
• Java since 1998
• Interests: Clean code, TDD, Code quality, Security, Architecture,
Gardening
• Lives in the Netherlands / married / three daughters / three dogs
%: whoami
• Peter Schuler
• Java developer / Architect @ Rabobank
• Trainer and coach
• Writing code since 1992
• Java since 1998
• Interests: Clean code, TDD, Code quality, Security, Architecture,
Gardening
• Lives in the Netherlands / married / three daughters / three dogs
I am also 2,04 meters. J
Agenda
• What do I mean with bigger?
• Why do we write unit tests?
• Why should they be bigger?
• How do you make them bigger?
• How big is big enough?
Unit test should have a bigger test scope
So we go from this:
Class
Unit Test
Unit Test Class
Class
Class
Class
To this:
Why unit test?
You tell me!
Join the word could:
livecloud.online/join/U446
Why unit test?
I was forced to by some ‘senior’ developer
Apparently we need coverage
If I don’t the build won’t pass
Is my code working?
Is my code STILL working?
Will this change affect other parts of the code?
Dare I make this change to the code?
Do I trust my code?
Do I trust code?
Why a bigger testscope?
Which design is better?
SubElement1MapperTest
The problem with being small
Response mapper
Sub Element 1 mapper
Sub Element 2 mapper
Enum 2 mapper
ResponseMapperTest
SubElement2MapperTest
Enum2MapperTest
The problem with being small
• Tightly coupled to the coding structure eg:
• When your code structure changes, your test structure will change
• This will make refactoring a hell
• So ..when you need them the most
…. small tests will actually work against you.
• The test cannot be translated to business concepts.
• You test classes … but not their interaction …
Let’s look at small scoped tests
• Especially classes at both ends of the hierarchy look silly.
• Can you discuss these tests with the business?
• Can you map them on a functional requirement?
https://martinfowler.com/articles/mocksArentStubs.html
Martin Fowler
Let’s do a little though experiment
• Let’s assume that these are
classes / components.
• How will we test that they do as
designed using mocks?
• Shoot!
https://youtu.be/IKwWu2w1gGk
Bigger scope is better
High level interface / service /
rest controller / sub-part
Sub Element 1 mapper
Sub Element 2 mapper
Enum 2 mapper
Unit Test
DAO
DB
TestDataGenerators
Test Infa Setup
MatcherHelpers
External JAR
Let’s look at bigger scoped tests
• So now we have tests that we can explain to the business.
• Let’s look at how to make them.
Hurdles when being bigger scoped
• They need more “plumbing code” to get set up.
• They need more asserts and more setup.
• Testing every small aspect might be to hard.
• They fail when the business requirements change.
Wait… that is actually a good thing!
Couple test to behaviour not stucture
https://www.facebook.com/notes/kent-beck/unit-tests/1726369154062608/
https://youtube.com/playlist?list=PLlmVY7qtgT_lkbrk9iZNizp978mVzpBKl
How to make them bigger - Plumbing
• Use Spring..
How to make them bigger - Plumbing
• Or just be your own dependency injection framework:
• Or perhaps use Google Guice
• But when you are using Spring, Spring will mostly do just fine.
How to make them bigger – Test Data
• Use TestBuilders to build Bigger Object Quicker
How to make them bigger – Test Data
• Chain test builders for better semantics. Go to town..
• Grow your own specific test semantics / DSL.
aRequest()
.with()
.twoApplications()
.existingMortgages()
.add(anAnuity())
.add(new CreditMortgageBuilder()
.setSaldo(20000)
.setLimit(40000))
.newHouse(450000)
.currentHouse(200000)
.build();
How to make them bigger – Asserts
• Bigger scope means more asserts.
• This drawback is harder to mitigate.
• Solutions:
• Apply clean code standards.
• Test only the small aspects of your who set.
• Make helper functions and delegate
• Split up your tests in multiple test classes for different aspects.
• I once split a calculation test class in positive, negative and weird cases.
How to make them bigger – Test all
• Bigger scope makes testing every possible mutation harder.
• Solution:
• Do not test everything BIG.
• It is still fine to write specific tests for specific classes.
• But please try to test against stable interfaces.
• And you can still test small aspects with a big test
Be Big and Small at the same time
• You can still be Big, but test a small aspect of your code.
• This also helps with having too many asserts.
How big should a unit test scope be?
• In scope:
• Everything that is a “pure function”
• Layers in your application.
• External JAR files
• Controllers
• DB’s -> can be unit tested easily these days.
• Out of scope:
• External network calls.
• But this is all a guideline … you are in control of your own fate J
What I want you to do
• Make your test scope bigger.
• Stop excessive mocking!
• Base your unit test on business data.
• But … do not ..
• … stop writing tests
• … stop feeling free to test small
• … only think big.

More Related Content

Similar to Bigger Unit Test Are Better

Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
Tyler Johnston
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
Steven Casey
 
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
Cefalo
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
Ganesh Kondal
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
Alan Christensen
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
Blue Elephant Consulting
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
Ferdous Mahmud Shaon
 
Unit testing
Unit testingUnit testing
Unit testing
PiXeL16
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
Einar Ingebrigtsen
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
Donny Wals
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
Donny Wals
 
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
michael.labriola
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
Ian Truslove
 
Clean code
Clean codeClean code
Clean code
Simon Sönnby
 
Tdd
TddTdd
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
Malinda Kapuruge
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
Duy Tan Geek
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
Pablo Villar
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
Shawn Jones
 

Similar to Bigger Unit Test Are Better (20)

Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
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
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
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
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
Clean code
Clean codeClean code
Clean code
 
Tdd
TddTdd
Tdd
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 

Recently uploaded

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 

Recently uploaded (20)

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 

Bigger Unit Test Are Better

  • 1. Bigger Unit Test Are Better why having many small unit test classes will slow you down
  • 2. %: whoami • Peter Schuler • Java developer @ Rabobank @ Tribe Wonen • Trainer and coach • Writing code since 1992 • Java since 1998 • Interests: Clean code, TDD, Code quality, Security, Architecture, Gardening • Lives in the Netherlands / married / three daughters / three dogs
  • 3. %: whoami • Peter Schuler • Java developer / Architect @ Rabobank • Trainer and coach • Writing code since 1992 • Java since 1998 • Interests: Clean code, TDD, Code quality, Security, Architecture, Gardening • Lives in the Netherlands / married / three daughters / three dogs I am also 2,04 meters. J
  • 4. Agenda • What do I mean with bigger? • Why do we write unit tests? • Why should they be bigger? • How do you make them bigger? • How big is big enough?
  • 5. Unit test should have a bigger test scope So we go from this: Class Unit Test Unit Test Class Class Class Class To this:
  • 6. Why unit test? You tell me! Join the word could: livecloud.online/join/U446
  • 7. Why unit test? I was forced to by some ‘senior’ developer Apparently we need coverage If I don’t the build won’t pass Is my code working? Is my code STILL working? Will this change affect other parts of the code? Dare I make this change to the code? Do I trust my code? Do I trust code?
  • 8. Why a bigger testscope? Which design is better?
  • 9. SubElement1MapperTest The problem with being small Response mapper Sub Element 1 mapper Sub Element 2 mapper Enum 2 mapper ResponseMapperTest SubElement2MapperTest Enum2MapperTest
  • 10. The problem with being small • Tightly coupled to the coding structure eg: • When your code structure changes, your test structure will change • This will make refactoring a hell • So ..when you need them the most …. small tests will actually work against you. • The test cannot be translated to business concepts. • You test classes … but not their interaction …
  • 11. Let’s look at small scoped tests • Especially classes at both ends of the hierarchy look silly. • Can you discuss these tests with the business? • Can you map them on a functional requirement?
  • 13. Let’s do a little though experiment • Let’s assume that these are classes / components. • How will we test that they do as designed using mocks? • Shoot!
  • 15. Bigger scope is better High level interface / service / rest controller / sub-part Sub Element 1 mapper Sub Element 2 mapper Enum 2 mapper Unit Test DAO DB TestDataGenerators Test Infa Setup MatcherHelpers External JAR
  • 16. Let’s look at bigger scoped tests • So now we have tests that we can explain to the business. • Let’s look at how to make them.
  • 17. Hurdles when being bigger scoped • They need more “plumbing code” to get set up. • They need more asserts and more setup. • Testing every small aspect might be to hard. • They fail when the business requirements change. Wait… that is actually a good thing!
  • 18. Couple test to behaviour not stucture https://www.facebook.com/notes/kent-beck/unit-tests/1726369154062608/ https://youtube.com/playlist?list=PLlmVY7qtgT_lkbrk9iZNizp978mVzpBKl
  • 19. How to make them bigger - Plumbing • Use Spring..
  • 20. How to make them bigger - Plumbing • Or just be your own dependency injection framework: • Or perhaps use Google Guice • But when you are using Spring, Spring will mostly do just fine.
  • 21. How to make them bigger – Test Data • Use TestBuilders to build Bigger Object Quicker
  • 22. How to make them bigger – Test Data • Chain test builders for better semantics. Go to town.. • Grow your own specific test semantics / DSL. aRequest() .with() .twoApplications() .existingMortgages() .add(anAnuity()) .add(new CreditMortgageBuilder() .setSaldo(20000) .setLimit(40000)) .newHouse(450000) .currentHouse(200000) .build();
  • 23. How to make them bigger – Asserts • Bigger scope means more asserts. • This drawback is harder to mitigate. • Solutions: • Apply clean code standards. • Test only the small aspects of your who set. • Make helper functions and delegate • Split up your tests in multiple test classes for different aspects. • I once split a calculation test class in positive, negative and weird cases.
  • 24. How to make them bigger – Test all • Bigger scope makes testing every possible mutation harder. • Solution: • Do not test everything BIG. • It is still fine to write specific tests for specific classes. • But please try to test against stable interfaces. • And you can still test small aspects with a big test
  • 25. Be Big and Small at the same time • You can still be Big, but test a small aspect of your code. • This also helps with having too many asserts.
  • 26. How big should a unit test scope be? • In scope: • Everything that is a “pure function” • Layers in your application. • External JAR files • Controllers • DB’s -> can be unit tested easily these days. • Out of scope: • External network calls. • But this is all a guideline … you are in control of your own fate J
  • 27. What I want you to do • Make your test scope bigger. • Stop excessive mocking! • Base your unit test on business data. • But … do not .. • … stop writing tests • … stop feeling free to test small • … only think big.