SlideShare a Scribd company logo
1 of 30
Download to read offline
/29@yegor256 1
Built-in Fake Objects
Yegor Bugayenko
/29@yegor256 2
“Mock objects are
simulated objects that
mimic the behavior of
real objects in
controlled ways”
/29@yegor256 3
Fake

Objects
Mocking
Frameworks
/29@yegor256 4
static String report(User user) {
return String.format(
“Balance of %s is %d USD”,
user.profile().name(),
user.account().balance().usd()
);
}
/29@yegor256 5
interface Profile {
String name();
}
interface User {
Profile profile();
Account account();
}
interface Account {
Balance balance();
}
interface Balance {
int usd();
}
/29@yegor256 6
@Test
void printsReport() {
User user = mock(User.class);
assertThat(
Foo.report(user),
containsString(“Balance of”)
);
}
Mockito
/29@yegor256 7
@Test
void printsReport() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
doReturn(“Jeffrey”).when(account).name();
Balance balance = mock(Balance.class);
doReturn(123).when(balance).usd();
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“Balance of Jeffrey is 123 USD”)
);
}
/29@yegor256 8
1. verbosity
/29@yegor256 9
@Test
void printsReport() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
doReturn(“Jeffrey”).when(account).name();
Balance balance = mock(Balance.class);
doReturn(123).when(balance).usd();
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“Balance of Jeffrey is 123 USD”)
);
}
String report(User user) {
return String.format(
“Balance of %s is %d USD”,
user.profile().name(),
user.account().balance().usd()
);
}
/29@yegor256 10
2. code duplication
/29@yegor256 11
@Test
void reportIncludesUserName() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
doReturn(“Jeffrey”).when(account).name();
Balance balance = mock(Balance.class);
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“Jeffrey”)
);
}
@Test
void reportIncludesBalanceInUSD() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
Balance balance = mock(Balance.class);
doReturn(123).when(balance).usd();
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“123 USD”)
);
}
/29@yegor256 12
3. complexity
/29@yegor256 13
example!!
/29@yegor256 14
4. fragility
because of coupling
/29@yegor256 15
@Test
void printsReport() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
doReturn(“Jeffrey”).when(account).name();
Balance balance = mock(Balance.class);
doReturn(123).when(balance).usd();
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“Balance of Jeffrey is 123 USD”)
);
}
String report(User user) {
return String.format(
“Balance of %s is %d USD”,
user.profile().name(),
user.account().balance().usd()
);
}
/29@yegor256 16
@Test
void printsReport() {
Profile profile = mock(Profile.class);
Account account = mock(Account.class);
doReturn(“Jeffrey”).when(account).name();
Balance balance = mock(Balance.class);
doReturn(123).when(balance).usd();
doReturn(balance).when(account).balance();
User user = mock(User.class);
doReturn(profile).when(user).profile();
doReturn(account).when(user).account();
assertThat(
Foo.report(user),
containsString(“Balance of Jeffrey is 123 USD”)
);
}
String report(User user) {
return String.format(
“Balance of %s is %d USD”,
user.profile().name(),
user.account().usd()
);
}
/29@yegor256 17
“Unit tests are your
safety net”
/29@yegor256 18
false positive
/29@yegor256 19
throw-away tests
/29@yegor256 20
a solution?

fake objects!
/29@yegor256 21
interface User {
Profile profile();
Account account();
class Fake {
Fake(String name, int balance) {
// ...
}
// ...
}
}
/29@yegor256 22
@Test
void printsReport() {
User user = new User.Fake(“Jeffrey”, 123);
assertThat(
Foo.report(user),
containsString(“Balance of Jeffrey is 123 USD”)
);
}
verbosity?
/29@yegor256 23
@Test
void reportIncludesUserName() {
User user = new User.Fake(“Jeffrey”);
assertThat(
Foo.report(user),
containsString(“Jeffrey”)
);
}
code duplication?
@Test
void reportIncludesBalanceInUSD() {
User user = new User.Fake(123);
assertThat(
Foo.report(user),
containsString(“123 USD”)
);
}
/29@yegor256 24
@Test
void reportIncludesUserName() {
User user = new User.Fake(“Jeffrey”);
assertThat(
Foo.report(user),
containsString(“Jeffrey”)
);
}
complexity?
@Test
void reportIncludesBalanceInUSD() {
User user = new User.Fake(123);
assertThat(
Foo.report(user),
containsString(“123 USD”)
);
}
/29@yegor256 25
String report(User user) {
return String.format(
“Balance of %s is %d USD”,
user.profile().name(),
user.account().balance().usd()
);
}
fragility?
@Test
void reportIncludesBalanceInUSD() {
User user = new User.Fake(123);
assertThat(
Foo.report(user),
containsString(“123 USD”)
);
}
/29@yegor256 26
no throw-away tests
any more
/29@yegor256 27
always ship them

together!
/29@yegor256 28
interface User {
Profile profile();
Account account();
class Fake {
}
}
class UserTest {
@Test
void hasBalance() {
User user = new User.Fake(123);
assertThat(
user.account().balance().usd(),
not(equalTo(0))
);
}
}
/29@yegor256 29
Fake

Objects
Mocking
Frameworks
/29@yegor256 30
Section 2.8
Don’t mock; use fakes

More Related Content

What's hot

Drupal 9 training ajax
Drupal 9 training ajaxDrupal 9 training ajax
Drupal 9 training ajaxNeelAndrew
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Dan Wahlin
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 formsEyal Vardi
 
Crash Course to SQL in PHP
Crash Course to SQL in PHPCrash Course to SQL in PHP
Crash Course to SQL in PHPwebhostingguy
 
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...sriram sarwan
 
Exemple de création de base
Exemple de création de baseExemple de création de base
Exemple de création de baseSaber LAJILI
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0Eyal Vardi
 
WordCamp Denver 2012 - Custom Meta Boxes
WordCamp Denver 2012 - Custom Meta BoxesWordCamp Denver 2012 - Custom Meta Boxes
WordCamp Denver 2012 - Custom Meta BoxesJeremy Green
 

What's hot (12)

8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
Drupal 9 training ajax
Drupal 9 training ajaxDrupal 9 training ajax
Drupal 9 training ajax
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Crash Course to SQL in PHP
Crash Course to SQL in PHPCrash Course to SQL in PHP
Crash Course to SQL in PHP
 
Chekout demistified
Chekout demistifiedChekout demistified
Chekout demistified
 
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
 
Exemple de création de base
Exemple de création de baseExemple de création de base
Exemple de création de base
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Hacking with YUI
Hacking with YUIHacking with YUI
Hacking with YUI
 
WordCamp Denver 2012 - Custom Meta Boxes
WordCamp Denver 2012 - Custom Meta BoxesWordCamp Denver 2012 - Custom Meta Boxes
WordCamp Denver 2012 - Custom Meta Boxes
 

Viewers also liked

ORM is a perfect anti-pattern
ORM is a perfect anti-patternORM is a perfect anti-pattern
ORM is a perfect anti-patternYegor Bugayenko
 
How Anemic Objects Kill OOP
How Anemic Objects Kill OOPHow Anemic Objects Kill OOP
How Anemic Objects Kill OOPYegor Bugayenko
 
Who Is a Software Architect?
Who Is a Software Architect?Who Is a Software Architect?
Who Is a Software Architect?Yegor Bugayenko
 
Management without managers
Management without managersManagement without managers
Management without managersYegor Bugayenko
 
eXtremely Distributed Software Development
eXtremely Distributed Software DevelopmenteXtremely Distributed Software Development
eXtremely Distributed Software DevelopmentYegor Bugayenko
 
How Do You Talk to Your Microservice?
How Do You Talk to Your Microservice?How Do You Talk to Your Microservice?
How Do You Talk to Your Microservice?Yegor Bugayenko
 
Keep Your Servers in GitHub
Keep Your Servers in GitHubKeep Your Servers in GitHub
Keep Your Servers in GitHubYegor Bugayenko
 
ORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternYegor Bugayenko
 
Need It Robust? Make It Fragile!
Need It Robust? Make It Fragile!Need It Robust? Make It Fragile!
Need It Robust? Make It Fragile!Yegor Bugayenko
 
Continuous Integration is Dead
Continuous Integration is DeadContinuous Integration is Dead
Continuous Integration is DeadYegor Bugayenko
 
How Do You Know When Your Product is Ready to be Shipped?
How Do You Know When Your Product is Ready to be Shipped?How Do You Know When Your Product is Ready to be Shipped?
How Do You Know When Your Product is Ready to be Shipped?Yegor Bugayenko
 
How Much Immutability Is Enough?
How Much Immutability Is Enough?How Much Immutability Is Enough?
How Much Immutability Is Enough?Yegor Bugayenko
 
Fail Fast. Into User's Face.
Fail Fast. Into User's Face.Fail Fast. Into User's Face.
Fail Fast. Into User's Face.Yegor Bugayenko
 
Practical Example of AOP with AspectJ
Practical Example of AOP with AspectJPractical Example of AOP with AspectJ
Practical Example of AOP with AspectJYegor Bugayenko
 

Viewers also liked (20)

ORM is a perfect anti-pattern
ORM is a perfect anti-patternORM is a perfect anti-pattern
ORM is a perfect anti-pattern
 
How Anemic Objects Kill OOP
How Anemic Objects Kill OOPHow Anemic Objects Kill OOP
How Anemic Objects Kill OOP
 
Object Oriented Lies
Object Oriented LiesObject Oriented Lies
Object Oriented Lies
 
Java vs OOP
Java vs OOPJava vs OOP
Java vs OOP
 
Who Is a Software Architect?
Who Is a Software Architect?Who Is a Software Architect?
Who Is a Software Architect?
 
Management without managers
Management without managersManagement without managers
Management without managers
 
ORM is offensive
ORM is offensiveORM is offensive
ORM is offensive
 
eXtremely Distributed Software Development
eXtremely Distributed Software DevelopmenteXtremely Distributed Software Development
eXtremely Distributed Software Development
 
How Do You Talk to Your Microservice?
How Do You Talk to Your Microservice?How Do You Talk to Your Microservice?
How Do You Talk to Your Microservice?
 
Keep Your Servers in GitHub
Keep Your Servers in GitHubKeep Your Servers in GitHub
Keep Your Servers in GitHub
 
ORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-Pattern
 
Need It Robust? Make It Fragile!
Need It Robust? Make It Fragile!Need It Robust? Make It Fragile!
Need It Robust? Make It Fragile!
 
Who Manages Who?
Who Manages Who?Who Manages Who?
Who Manages Who?
 
Meetings Or Discipline
Meetings Or DisciplineMeetings Or Discipline
Meetings Or Discipline
 
OOP Is Dead? Not Yet!
OOP Is Dead? Not Yet!OOP Is Dead? Not Yet!
OOP Is Dead? Not Yet!
 
Continuous Integration is Dead
Continuous Integration is DeadContinuous Integration is Dead
Continuous Integration is Dead
 
How Do You Know When Your Product is Ready to be Shipped?
How Do You Know When Your Product is Ready to be Shipped?How Do You Know When Your Product is Ready to be Shipped?
How Do You Know When Your Product is Ready to be Shipped?
 
How Much Immutability Is Enough?
How Much Immutability Is Enough?How Much Immutability Is Enough?
How Much Immutability Is Enough?
 
Fail Fast. Into User's Face.
Fail Fast. Into User's Face.Fail Fast. Into User's Face.
Fail Fast. Into User's Face.
 
Practical Example of AOP with AspectJ
Practical Example of AOP with AspectJPractical Example of AOP with AspectJ
Practical Example of AOP with AspectJ
 

Similar to Built-in Fake Objects

Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfShaiAlmog1
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»e-Legion
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumnameEmanuele Quinto
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityWashington Botelho
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Yango Alexander Colmenares
 
Being Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring ReactorBeing Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring ReactorMax Huang
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfARORACOCKERY2111
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptxMuqaddarNiazi1
 
Creating a Facebook Clone - Part XXV.pdf
Creating a Facebook Clone - Part XXV.pdfCreating a Facebook Clone - Part XXV.pdf
Creating a Facebook Clone - Part XXV.pdfShaiAlmog1
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"epamspb
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Android Testing
Android TestingAndroid Testing
Android TestingEvan Lin
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0Tobias Meixner
 

Similar to Built-in Fake Objects (20)

Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
 
Drupal csu-open atriumname
Drupal csu-open atriumnameDrupal csu-open atriumname
Drupal csu-open atriumname
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrity
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)
 
Being Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring ReactorBeing Functional on Reactive Streams with Spring Reactor
Being Functional on Reactive Streams with Spring Reactor
 
Functions
FunctionsFunctions
Functions
 
Road to Async Nirvana
Road to Async NirvanaRoad to Async Nirvana
Road to Async Nirvana
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Flutter
FlutterFlutter
Flutter
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
Creating a Facebook Clone - Part XXV.pdf
Creating a Facebook Clone - Part XXV.pdfCreating a Facebook Clone - Part XXV.pdf
Creating a Facebook Clone - Part XXV.pdf
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Android Testing
Android TestingAndroid Testing
Android Testing
 
Geb qa fest2017
Geb qa fest2017Geb qa fest2017
Geb qa fest2017
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
 

More from Yegor Bugayenko

Can Distributed Teams Deliver Quality?
Can Distributed Teams Deliver Quality?Can Distributed Teams Deliver Quality?
Can Distributed Teams Deliver Quality?Yegor Bugayenko
 
Are You Sure You Are Not a Micromanager?
Are You Sure You Are Not a Micromanager?Are You Sure You Are Not a Micromanager?
Are You Sure You Are Not a Micromanager?Yegor Bugayenko
 
On Requirements Management (Demotivate Them Right)
On Requirements Management (Demotivate Them Right)On Requirements Management (Demotivate Them Right)
On Requirements Management (Demotivate Them Right)Yegor Bugayenko
 
My Experience of 1000 Interviews
My Experience of 1000 InterviewsMy Experience of 1000 Interviews
My Experience of 1000 InterviewsYegor Bugayenko
 
Are you sure you are not a micromanager?
Are you sure you are not a micromanager?Are you sure you are not a micromanager?
Are you sure you are not a micromanager?Yegor Bugayenko
 
Quality Assurance vs. Testing
Quality Assurance vs. TestingQuality Assurance vs. Testing
Quality Assurance vs. TestingYegor Bugayenko
 
Typical Pitfalls in Testing
Typical Pitfalls in TestingTypical Pitfalls in Testing
Typical Pitfalls in TestingYegor Bugayenko
 
Software Testing Pitfalls
Software Testing PitfallsSoftware Testing Pitfalls
Software Testing PitfallsYegor Bugayenko
 
Five Trends We Are Afraid Of
Five Trends We Are Afraid OfFive Trends We Are Afraid Of
Five Trends We Are Afraid OfYegor Bugayenko
 
Who Cares About Quality?
Who Cares About Quality?Who Cares About Quality?
Who Cares About Quality?Yegor Bugayenko
 
Zold: a cryptocurrency without Blockchain
Zold: a cryptocurrency without BlockchainZold: a cryptocurrency without Blockchain
Zold: a cryptocurrency without BlockchainYegor Bugayenko
 
How to Cut Corners and Stay Cool
How to Cut Corners and Stay CoolHow to Cut Corners and Stay Cool
How to Cut Corners and Stay CoolYegor Bugayenko
 
Java Annotations Are a Bad Idea
Java Annotations Are a Bad IdeaJava Annotations Are a Bad Idea
Java Annotations Are a Bad IdeaYegor Bugayenko
 

More from Yegor Bugayenko (20)

Can Distributed Teams Deliver Quality?
Can Distributed Teams Deliver Quality?Can Distributed Teams Deliver Quality?
Can Distributed Teams Deliver Quality?
 
Are You Sure You Are Not a Micromanager?
Are You Sure You Are Not a Micromanager?Are You Sure You Are Not a Micromanager?
Are You Sure You Are Not a Micromanager?
 
On Requirements Management (Demotivate Them Right)
On Requirements Management (Demotivate Them Right)On Requirements Management (Demotivate Them Right)
On Requirements Management (Demotivate Them Right)
 
My Experience of 1000 Interviews
My Experience of 1000 InterviewsMy Experience of 1000 Interviews
My Experience of 1000 Interviews
 
Are you sure you are not a micromanager?
Are you sure you are not a micromanager?Are you sure you are not a micromanager?
Are you sure you are not a micromanager?
 
Quality Assurance vs. Testing
Quality Assurance vs. TestingQuality Assurance vs. Testing
Quality Assurance vs. Testing
 
Is Java Getting Better?
Is Java Getting Better?Is Java Getting Better?
Is Java Getting Better?
 
Typical Pitfalls in Testing
Typical Pitfalls in TestingTypical Pitfalls in Testing
Typical Pitfalls in Testing
 
Software Testing Pitfalls
Software Testing PitfallsSoftware Testing Pitfalls
Software Testing Pitfalls
 
Five Trends We Are Afraid Of
Five Trends We Are Afraid OfFive Trends We Are Afraid Of
Five Trends We Are Afraid Of
 
Experts vs Expertise
Experts vs ExpertiseExperts vs Expertise
Experts vs Expertise
 
Who Cares About Quality?
Who Cares About Quality?Who Cares About Quality?
Who Cares About Quality?
 
Quantity vs. Quality
Quantity vs. QualityQuantity vs. Quality
Quantity vs. Quality
 
Experts vs Expertise
Experts vs ExpertiseExperts vs Expertise
Experts vs Expertise
 
Zold: a cryptocurrency without Blockchain
Zold: a cryptocurrency without BlockchainZold: a cryptocurrency without Blockchain
Zold: a cryptocurrency without Blockchain
 
Life Without Blockchain
Life Without BlockchainLife Without Blockchain
Life Without Blockchain
 
How to Cut Corners and Stay Cool
How to Cut Corners and Stay CoolHow to Cut Corners and Stay Cool
How to Cut Corners and Stay Cool
 
Math or Love?
Math or Love?Math or Love?
Math or Love?
 
How much do you cost?
How much do you cost?How much do you cost?
How much do you cost?
 
Java Annotations Are a Bad Idea
Java Annotations Are a Bad IdeaJava Annotations Are a Bad Idea
Java Annotations Are a Bad Idea
 

Recently uploaded

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Built-in Fake Objects

  • 1. /29@yegor256 1 Built-in Fake Objects Yegor Bugayenko
  • 2. /29@yegor256 2 “Mock objects are simulated objects that mimic the behavior of real objects in controlled ways”
  • 4. /29@yegor256 4 static String report(User user) { return String.format( “Balance of %s is %d USD”, user.profile().name(), user.account().balance().usd() ); }
  • 5. /29@yegor256 5 interface Profile { String name(); } interface User { Profile profile(); Account account(); } interface Account { Balance balance(); } interface Balance { int usd(); }
  • 6. /29@yegor256 6 @Test void printsReport() { User user = mock(User.class); assertThat( Foo.report(user), containsString(“Balance of”) ); } Mockito
  • 7. /29@yegor256 7 @Test void printsReport() { Profile profile = mock(Profile.class); Account account = mock(Account.class); doReturn(“Jeffrey”).when(account).name(); Balance balance = mock(Balance.class); doReturn(123).when(balance).usd(); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“Balance of Jeffrey is 123 USD”) ); }
  • 9. /29@yegor256 9 @Test void printsReport() { Profile profile = mock(Profile.class); Account account = mock(Account.class); doReturn(“Jeffrey”).when(account).name(); Balance balance = mock(Balance.class); doReturn(123).when(balance).usd(); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“Balance of Jeffrey is 123 USD”) ); } String report(User user) { return String.format( “Balance of %s is %d USD”, user.profile().name(), user.account().balance().usd() ); }
  • 10. /29@yegor256 10 2. code duplication
  • 11. /29@yegor256 11 @Test void reportIncludesUserName() { Profile profile = mock(Profile.class); Account account = mock(Account.class); doReturn(“Jeffrey”).when(account).name(); Balance balance = mock(Balance.class); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“Jeffrey”) ); } @Test void reportIncludesBalanceInUSD() { Profile profile = mock(Profile.class); Account account = mock(Account.class); Balance balance = mock(Balance.class); doReturn(123).when(balance).usd(); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“123 USD”) ); }
  • 15. /29@yegor256 15 @Test void printsReport() { Profile profile = mock(Profile.class); Account account = mock(Account.class); doReturn(“Jeffrey”).when(account).name(); Balance balance = mock(Balance.class); doReturn(123).when(balance).usd(); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“Balance of Jeffrey is 123 USD”) ); } String report(User user) { return String.format( “Balance of %s is %d USD”, user.profile().name(), user.account().balance().usd() ); }
  • 16. /29@yegor256 16 @Test void printsReport() { Profile profile = mock(Profile.class); Account account = mock(Account.class); doReturn(“Jeffrey”).when(account).name(); Balance balance = mock(Balance.class); doReturn(123).when(balance).usd(); doReturn(balance).when(account).balance(); User user = mock(User.class); doReturn(profile).when(user).profile(); doReturn(account).when(user).account(); assertThat( Foo.report(user), containsString(“Balance of Jeffrey is 123 USD”) ); } String report(User user) { return String.format( “Balance of %s is %d USD”, user.profile().name(), user.account().usd() ); }
  • 17. /29@yegor256 17 “Unit tests are your safety net”
  • 21. /29@yegor256 21 interface User { Profile profile(); Account account(); class Fake { Fake(String name, int balance) { // ... } // ... } }
  • 22. /29@yegor256 22 @Test void printsReport() { User user = new User.Fake(“Jeffrey”, 123); assertThat( Foo.report(user), containsString(“Balance of Jeffrey is 123 USD”) ); } verbosity?
  • 23. /29@yegor256 23 @Test void reportIncludesUserName() { User user = new User.Fake(“Jeffrey”); assertThat( Foo.report(user), containsString(“Jeffrey”) ); } code duplication? @Test void reportIncludesBalanceInUSD() { User user = new User.Fake(123); assertThat( Foo.report(user), containsString(“123 USD”) ); }
  • 24. /29@yegor256 24 @Test void reportIncludesUserName() { User user = new User.Fake(“Jeffrey”); assertThat( Foo.report(user), containsString(“Jeffrey”) ); } complexity? @Test void reportIncludesBalanceInUSD() { User user = new User.Fake(123); assertThat( Foo.report(user), containsString(“123 USD”) ); }
  • 25. /29@yegor256 25 String report(User user) { return String.format( “Balance of %s is %d USD”, user.profile().name(), user.account().balance().usd() ); } fragility? @Test void reportIncludesBalanceInUSD() { User user = new User.Fake(123); assertThat( Foo.report(user), containsString(“123 USD”) ); }
  • 27. /29@yegor256 27 always ship them
 together!
  • 28. /29@yegor256 28 interface User { Profile profile(); Account account(); class Fake { } } class UserTest { @Test void hasBalance() { User user = new User.Fake(123); assertThat( user.account().balance().usd(), not(equalTo(0)) ); } }