SlideShare a Scribd company logo
07 Testing - Techniques
Enginyeria del Software 3
1
@drpicox — 2020
Summary
• Levels of Testing

• FIRST properties

• AAA structure

• Code Coverage

• Regression Tests

• Test doubles
2
Summary
• Levels of Testing
• FIRST properties

• AAA structure

• Code Coverage

• Regression Tests

• Test doubles
3
Levels of Testing
• Acceptance Tests

• Programmers Tests
4
Acceptance Tests
• Readable by Stakeholders

• Natural language

• Aligned to Requirements

• High level

• Integrate many levels in the test

• Slow
5
Programmers Tests
• Fast to run

• Quick to code

• Fine grained

• Close to Requirements (Business rules)
6
Levels and TDD
7
Summary
• Levels of Testing

• FIRST properties
• AAA structure

• Code Coverage

• Regression Tests

• Test doubles
8
FIRST properties
• Fast

• Isolates

• Repeatable

• Self-validating

• Timely
9
Fast
• Many hundreds or thousands per second

• Avoid slow logic

• Data bases

• External services

• Intensive computations

• ...
10
Isolates
• Failure reasons become obvious

• Each test runs individually

• No assumed initial state

• Not require other test run first

• Can run alone

• Can run in random order

• new , new , new

• ...
11
Repeatable
• Run repeatedly in any order, any time

• No side effects

• No globals/statics

• No time

• No random

• No databases

• No services

• No split test logic

• ...
12
Self-validating
• No manual evaluation required

• Only two outcomes

• Red/Green

• Fail/Pass
13
Timely
• Written before the code

• If you write test after code:

• You do not follow TDD

• You are not sure that the test works

• You forget test behaviours

• Your tests become useless

• You feel cheeting

• ...
14
Example
const notebook = new Notebook()
test("add a contact", () => {
notebook.add("John", 1234)
expect(notebook.get("John")).toBe(1234)
})
test("update contact", () => {
notebook.update("John", 3456)
expect(notebook.get("John")).toBe(3456)
})
test("remove a contact", () => {
notebook.remove("John")
expect(notebook.get("John")).toBeNull()
})
15
Example
test("add a contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
expect(notebook.get("John")).toBe(1234)
})
test("update contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
notebook.update("John", 3456)
expect(notebook.get("John")).toBe(3456)
})
test("remove a contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
notebook.remove("John")
expect(notebook.get("John")).toBeNull()
})
16
Example
// Date changes each time
new Date();
// Result changes each call
Random.next();
// We are accessing a static/global
Notebook.add("John", 1234);
// Global + It is not self-validated
if (notebook.get("John") === 1234)
System.out.println("Sucess")
17
Summary
• Levels of Testing

• FIRST properties

• AAA structure
• Code Coverage

• Regression Tests

• Test doubles
18
AAA Structure
• Arrange

• Prepare the initial states

• Call news and required sets before act

• Act

• Execute the actions required by the test

• Assert

• Gather results

• Expect the result values
19
AAA Structure
• Order is always kept 

• Steps are not mixed

• Expect always simple results
20
Example
test("manage contacts", () => {
const notebook = new Notebook() // Arrange
notebook.add("John", 1234) // Act
expect(notebook.get("John")).toBe(1234) // Assert
notebook.update("John", 3456) // Act
expect(notebook.get("John")).toBe(3456) // Assert
notebook.delete("John") // Act
expect(notebook.get("John")).toBeNull() // Assert
})
21
Example
test("add contact", () => {
// Arrange
const notebook = new Notebook()
// Act
notebook.add("John", 1234)
// Assert
expect(notebook.get("John")).toBe(1234)
})
test("update contact", () => {
// Arrange
const notebook = new Notebook()
notebook.add("John", 1234)
// Act
notebook.update("John", 3456)
// Assert
expect(notebook.get("John")).toBe(3456)
})
...
22
Summary
• Levels of Testing

• FIRST properties

• AAA structure

• Code Coverage
• Regression Tests

• Test doubles
23
Code Coverage
24
Code Tested
Code Existing
%
Exemple
test("add contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
expect(notebook.get("John")).toBe(1234)
})
class Notebook {
add(name, phone) {
if (map.contains(name))
throw new Error(`Cannot add twice ${name}`)
map.put(name, phone)
}
}
25
Code Coverage: 66%
Uncovered line
Exemple
test("add contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
expect(notebook.get("John")).toBe(1234)
})
test('cannot add a duplicated contact', () => {
const notebook = new Notebook()
notebook.add("John", 1234)
expect(() => notebook.add('John', 1111)).toThrow()
})
class Notebook {
add(name, phone) {
if (map.contains(name))
throw new Error(`Cannot add twice ${name}`)
map.put(name, phone)
}
}
26
Code Coverage: 100%
Exemple
test("add contact", () => {
const notebook = new Notebook()
notebook.add("John", 1234)
expect(notebook.get("John")).toBe(1234)
})
class Notebook {
add(name, phone) {
map.put(name, phone)
}
}
27
Code Coverage: 100%
Número de tests
• 1 test base

• 1 test per condition

• &&, ||, if, while, for, ...

• 1 test per switch cases + 1 for default 

• Default is always present, even if it is not written
28
Cannot cover
• Main

• Dates

• Randoms

• Network

• ...
29
–Robert C. Martin
“Every well designed system has at least one dirty
component, usually associated with main. Nothing
outside this component depends on anything inside
it. All dependencies point outward. This is where
you put switches, factories, and IOC.”
30
https://twitter.com/unclebobmartin/status/1122138039390806016
Quality
• 100% Code Coverage DO NOT ensure correctness

• With TDD Code Coverage should be 100%

• It is a hint

• it reveals what went wrong

• what we missed

• which cases we implemented but not planned
31
Summary
• Levels of Testing

• FIRST properties

• AAA structure

• Code Coverage

• Regression Tests
• Test doubles
32
Serius Banking
test("deposit cash", () => {
const bank = new Bank()
bank.createAccount("John")
bank.deposit("John", 100)
expect(bank.get("John")).toBe(100)
})
class Bank {
deposit(name, amount) {
accounts.forEach(account => {
account.desposit += amount
})
}
}
33
🃏
Serius Banking
describe("regression tests", () => {
test("deposit cash into one single account", () => {
const bank = new Bank()
bank.createAccount("John")
bank.createAccount("Maria")
bank.deposit("John", 100)
expect(bank.get("Maria")).toBe(0)
expect(bank.get("John")).toBe(100)
})
})
34
🃏
Summary
• Levels of Testing

• FIRST properties

• AAA structure

• Code Coverage

• Regression Tests

• Test doubles
35
Test Doubles
• Replaces data/object with one created by the test

• 5 types

• Dummy

• Stub

• Spy

• Mock

• Fake
36
Dummy
• Null, 0 or a plain value that can replace an argument
37
test("count created accounts", () => {
const bank = new Bank()
bank.createAccount("John", null)
expect(bank.count()).toBe(1)
})
class Bank {
createAccount(name, fiscalData) {
accounts.put(name, fiscalData)
}
}
Stub
• A value need for the test that the code uses
38
test("gives heads", () => {
const random = {
next() {
return 0
},
}
const result = flipCoin(random)
expect(result).toBe("head")
})
function flipCoin(random) {
if (random.next() < 0.5) return "head"
return "tails"
}
Spy
• Method that remembers its calls
39
test("hello world", () => {
const log = []
const outputSpy = message => {
log.push(message)
}
sayHello(outputSpy)
expect(log).toEqual(["hello world"])
})
function sayHello(output) {
output("hello world")
}
Mock
• A spy that validates correctness and knows the object
40
class DiskMock {
log = [];
move(cylinder) {
this.log.push('move', cylinder);
}
write(data) {
this.log.push('write', data)
}
isFormatted() {
return this.log.equals('move', 0, 'write', 0)
}
}
test('formats a disk', () => {
const disk = new DiskMock();
format(disk);
expect(disk.isFormatted()).toBeTrue();
})
Fake
• An functional object that replaces an original one
41
test("deposit cash", () => {
const db = new InMemoryDB()
const bank = new Bank(db)
bank.createAccount("John")
bank.deposit("John", 100)
expect(bank.get("John")).toBe(100)
})
Confidence
• Test Doubles may Reduce Coverage

• Although, some cases are necessary

• Test Doubles Reduce Confidence
42
Summary
• Levels of Testing

• FIRST properties

• AAA structure

• Code Coverage

• Regression Tests

• Test doubles
43
Homework
• http://misko.hevery.com/code-reviewers-guide/
44

More Related Content

PDF
ES3-2020-06 Test Driven Development (TDD)
PDF
TDD CrashCourse Part4: Improving Testing
KEY
Inside PyMongo - MongoNYC
PDF
Introduction to web programming for java and c# programmers by @drpicox
PDF
TDD CrashCourse Part5: Testing Techniques
PDF
ReactJS for Programmers
PDF
Pyconie 2012
PDF
ES3-2020-P3 TDD Calculator
ES3-2020-06 Test Driven Development (TDD)
TDD CrashCourse Part4: Improving Testing
Inside PyMongo - MongoNYC
Introduction to web programming for java and c# programmers by @drpicox
TDD CrashCourse Part5: Testing Techniques
ReactJS for Programmers
Pyconie 2012
ES3-2020-P3 TDD Calculator

What's hot (20)

PDF
Redux for ReactJS Programmers
PDF
JS and patterns
PDF
Testing, Learning and Professionalism — 20171214
PPT
2012 JDays Bad Tests Good Tests
PPTX
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
PDF
33rd Degree 2013, Bad Tests, Good Tests
PDF
Spock Testing Framework - The Next Generation
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
PDF
Java 7 LavaJUG
PDF
Spock framework
PDF
Software Testing - Invited Lecture at UNSW Sydney
PDF
GMock framework
PPTX
Smarter Testing with Spock
PPTX
Unit testing patterns for concurrent code
PPTX
Smarter Testing With Spock
PDF
The Ring programming language version 1.6 book - Part 184 of 189
PPTX
Building unit tests correctly
PPTX
TDD Training
PDF
Spock Framework
DOCX
My java file
Redux for ReactJS Programmers
JS and patterns
Testing, Learning and Professionalism — 20171214
2012 JDays Bad Tests Good Tests
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
33rd Degree 2013, Bad Tests, Good Tests
Spock Testing Framework - The Next Generation
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 LavaJUG
Spock framework
Software Testing - Invited Lecture at UNSW Sydney
GMock framework
Smarter Testing with Spock
Unit testing patterns for concurrent code
Smarter Testing With Spock
The Ring programming language version 1.6 book - Part 184 of 189
Building unit tests correctly
TDD Training
Spock Framework
My java file
Ad

Similar to ES3-2020-07 Testing techniques (20)

PPTX
Iterative architecture
PDF
TDD CrashCourse Part3: TDD Techniques
PPTX
Unit test candidate solutions
PPTX
Why learn new programming languages
PDF
TDD Trade-Offs @Softwerkskammer Karlsruhe
PDF
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
PDF
Bdd for-dso-1227123516572504-8
KEY
Tdd for BT E2E test community
PDF
Advanced Django
PDF
Mockist vs. Classicists TDD
PDF
The Ring programming language version 1.5 book - Part 8 of 31
PDF
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
PDF
Programming exercises
PDF
The Ring programming language version 1.7 book - Part 48 of 196
PDF
Wann soll ich mocken?
PDF
The Ring programming language version 1.10 book - Part 22 of 212
PPTX
Legacy Code Kata v3.0
PDF
Unit Test and TDD
PPT
Using xUnit as a Swiss-Aarmy Testing Toolkit
Iterative architecture
TDD CrashCourse Part3: TDD Techniques
Unit test candidate solutions
Why learn new programming languages
TDD Trade-Offs @Softwerkskammer Karlsruhe
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Bdd for-dso-1227123516572504-8
Tdd for BT E2E test community
Advanced Django
Mockist vs. Classicists TDD
The Ring programming language version 1.5 book - Part 8 of 31
Por qué usar Spock en lugar de JUnit / Mockito para tus tests Java - Codemoti...
Programming exercises
The Ring programming language version 1.7 book - Part 48 of 196
Wann soll ich mocken?
The Ring programming language version 1.10 book - Part 22 of 212
Legacy Code Kata v3.0
Unit Test and TDD
Using xUnit as a Swiss-Aarmy Testing Toolkit
Ad

More from David Rodenas (16)

PDF
TDD CrashCourse Part2: TDD
PDF
TDD CrashCourse Part1: Testing
PDF
Be professional: We Rule the World
PDF
ES3-2020-P2 Bowling Game Kata
PDF
ES3-2020-05 Testing
PDF
Vespres
PDF
Faster web pages
PDF
Basic Tutorial of React for Programmers
PPTX
From high school to university and work
PDF
Modules in angular 2.0 beta.1
PDF
Freelance i Enginyeria
PDF
Angular 1.X Community and API Decissions
PDF
MVS: An angular MVC
PDF
Mvc - Model: the great forgotten
PDF
(automatic) Testing: from business to university and back
PDF
Testing: ¿what, how, why?
TDD CrashCourse Part2: TDD
TDD CrashCourse Part1: Testing
Be professional: We Rule the World
ES3-2020-P2 Bowling Game Kata
ES3-2020-05 Testing
Vespres
Faster web pages
Basic Tutorial of React for Programmers
From high school to university and work
Modules in angular 2.0 beta.1
Freelance i Enginyeria
Angular 1.X Community and API Decissions
MVS: An angular MVC
Mvc - Model: the great forgotten
(automatic) Testing: from business to university and back
Testing: ¿what, how, why?

Recently uploaded (20)

PPT
introduction to datamining and warehousing
PDF
PPT on Performance Review to get promotions
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
additive manufacturing of ss316l using mig welding
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT
Mechanical Engineering MATERIALS Selection
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Artificial Intelligence
introduction to datamining and warehousing
PPT on Performance Review to get promotions
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
additive manufacturing of ss316l using mig welding
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Foundation to blockchain - A guide to Blockchain Tech
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
UNIT 4 Total Quality Management .pptx
Lecture Notes Electrical Wiring System Components
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Current and future trends in Computer Vision.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mechanical Engineering MATERIALS Selection
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
573137875-Attendance-Management-System-original
bas. eng. economics group 4 presentation 1.pptx
Artificial Intelligence

ES3-2020-07 Testing techniques

  • 1. 07 Testing - Techniques Enginyeria del Software 3 1 @drpicox — 2020
  • 2. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 2
  • 3. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 3
  • 4. Levels of Testing • Acceptance Tests • Programmers Tests 4
  • 5. Acceptance Tests • Readable by Stakeholders • Natural language • Aligned to Requirements • High level • Integrate many levels in the test • Slow 5
  • 6. Programmers Tests • Fast to run • Quick to code • Fine grained • Close to Requirements (Business rules) 6
  • 8. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 8
  • 9. FIRST properties • Fast • Isolates • Repeatable • Self-validating • Timely 9
  • 10. Fast • Many hundreds or thousands per second • Avoid slow logic • Data bases • External services • Intensive computations • ... 10
  • 11. Isolates • Failure reasons become obvious • Each test runs individually • No assumed initial state • Not require other test run first • Can run alone • Can run in random order • new , new , new • ... 11
  • 12. Repeatable • Run repeatedly in any order, any time • No side effects • No globals/statics • No time • No random • No databases • No services • No split test logic • ... 12
  • 13. Self-validating • No manual evaluation required • Only two outcomes • Red/Green • Fail/Pass 13
  • 14. Timely • Written before the code • If you write test after code: • You do not follow TDD • You are not sure that the test works • You forget test behaviours • Your tests become useless • You feel cheeting • ... 14
  • 15. Example const notebook = new Notebook() test("add a contact", () => { notebook.add("John", 1234) expect(notebook.get("John")).toBe(1234) }) test("update contact", () => { notebook.update("John", 3456) expect(notebook.get("John")).toBe(3456) }) test("remove a contact", () => { notebook.remove("John") expect(notebook.get("John")).toBeNull() }) 15
  • 16. Example test("add a contact", () => { const notebook = new Notebook() notebook.add("John", 1234) expect(notebook.get("John")).toBe(1234) }) test("update contact", () => { const notebook = new Notebook() notebook.add("John", 1234) notebook.update("John", 3456) expect(notebook.get("John")).toBe(3456) }) test("remove a contact", () => { const notebook = new Notebook() notebook.add("John", 1234) notebook.remove("John") expect(notebook.get("John")).toBeNull() }) 16
  • 17. Example // Date changes each time new Date(); // Result changes each call Random.next(); // We are accessing a static/global Notebook.add("John", 1234); // Global + It is not self-validated if (notebook.get("John") === 1234) System.out.println("Sucess") 17
  • 18. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 18
  • 19. AAA Structure • Arrange • Prepare the initial states • Call news and required sets before act • Act • Execute the actions required by the test • Assert • Gather results • Expect the result values 19
  • 20. AAA Structure • Order is always kept • Steps are not mixed • Expect always simple results 20
  • 21. Example test("manage contacts", () => { const notebook = new Notebook() // Arrange notebook.add("John", 1234) // Act expect(notebook.get("John")).toBe(1234) // Assert notebook.update("John", 3456) // Act expect(notebook.get("John")).toBe(3456) // Assert notebook.delete("John") // Act expect(notebook.get("John")).toBeNull() // Assert }) 21
  • 22. Example test("add contact", () => { // Arrange const notebook = new Notebook() // Act notebook.add("John", 1234) // Assert expect(notebook.get("John")).toBe(1234) }) test("update contact", () => { // Arrange const notebook = new Notebook() notebook.add("John", 1234) // Act notebook.update("John", 3456) // Assert expect(notebook.get("John")).toBe(3456) }) ... 22
  • 23. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 23
  • 25. Exemple test("add contact", () => { const notebook = new Notebook() notebook.add("John", 1234) expect(notebook.get("John")).toBe(1234) }) class Notebook { add(name, phone) { if (map.contains(name)) throw new Error(`Cannot add twice ${name}`) map.put(name, phone) } } 25 Code Coverage: 66% Uncovered line
  • 26. Exemple test("add contact", () => { const notebook = new Notebook() notebook.add("John", 1234) expect(notebook.get("John")).toBe(1234) }) test('cannot add a duplicated contact', () => { const notebook = new Notebook() notebook.add("John", 1234) expect(() => notebook.add('John', 1111)).toThrow() }) class Notebook { add(name, phone) { if (map.contains(name)) throw new Error(`Cannot add twice ${name}`) map.put(name, phone) } } 26 Code Coverage: 100%
  • 27. Exemple test("add contact", () => { const notebook = new Notebook() notebook.add("John", 1234) expect(notebook.get("John")).toBe(1234) }) class Notebook { add(name, phone) { map.put(name, phone) } } 27 Code Coverage: 100%
  • 28. Número de tests • 1 test base • 1 test per condition • &&, ||, if, while, for, ... • 1 test per switch cases + 1 for default • Default is always present, even if it is not written 28
  • 29. Cannot cover • Main • Dates • Randoms • Network • ... 29
  • 30. –Robert C. Martin “Every well designed system has at least one dirty component, usually associated with main. Nothing outside this component depends on anything inside it. All dependencies point outward. This is where you put switches, factories, and IOC.” 30 https://twitter.com/unclebobmartin/status/1122138039390806016
  • 31. Quality • 100% Code Coverage DO NOT ensure correctness • With TDD Code Coverage should be 100% • It is a hint • it reveals what went wrong • what we missed • which cases we implemented but not planned 31
  • 32. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 32
  • 33. Serius Banking test("deposit cash", () => { const bank = new Bank() bank.createAccount("John") bank.deposit("John", 100) expect(bank.get("John")).toBe(100) }) class Bank { deposit(name, amount) { accounts.forEach(account => { account.desposit += amount }) } } 33 🃏
  • 34. Serius Banking describe("regression tests", () => { test("deposit cash into one single account", () => { const bank = new Bank() bank.createAccount("John") bank.createAccount("Maria") bank.deposit("John", 100) expect(bank.get("Maria")).toBe(0) expect(bank.get("John")).toBe(100) }) }) 34 🃏
  • 35. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 35
  • 36. Test Doubles • Replaces data/object with one created by the test • 5 types • Dummy • Stub • Spy • Mock • Fake 36
  • 37. Dummy • Null, 0 or a plain value that can replace an argument 37 test("count created accounts", () => { const bank = new Bank() bank.createAccount("John", null) expect(bank.count()).toBe(1) }) class Bank { createAccount(name, fiscalData) { accounts.put(name, fiscalData) } }
  • 38. Stub • A value need for the test that the code uses 38 test("gives heads", () => { const random = { next() { return 0 }, } const result = flipCoin(random) expect(result).toBe("head") }) function flipCoin(random) { if (random.next() < 0.5) return "head" return "tails" }
  • 39. Spy • Method that remembers its calls 39 test("hello world", () => { const log = [] const outputSpy = message => { log.push(message) } sayHello(outputSpy) expect(log).toEqual(["hello world"]) }) function sayHello(output) { output("hello world") }
  • 40. Mock • A spy that validates correctness and knows the object 40 class DiskMock { log = []; move(cylinder) { this.log.push('move', cylinder); } write(data) { this.log.push('write', data) } isFormatted() { return this.log.equals('move', 0, 'write', 0) } } test('formats a disk', () => { const disk = new DiskMock(); format(disk); expect(disk.isFormatted()).toBeTrue(); })
  • 41. Fake • An functional object that replaces an original one 41 test("deposit cash", () => { const db = new InMemoryDB() const bank = new Bank(db) bank.createAccount("John") bank.deposit("John", 100) expect(bank.get("John")).toBe(100) })
  • 42. Confidence • Test Doubles may Reduce Coverage • Although, some cases are necessary • Test Doubles Reduce Confidence 42
  • 43. Summary • Levels of Testing • FIRST properties • AAA structure • Code Coverage • Regression Tests • Test doubles 43