SlideShare uma empresa Scribd 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.

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Último

Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
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
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
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
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
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
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 

Último (20)

Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
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
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
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
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
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
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 

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.