approval testing · “the coding dojo handbook” ... enjoy the following coding activities?...

34
Approval Testing Introduction

Upload: others

Post on 14-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Approval TestingIntroduction

Page 2: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Emily Bache

Technical Agile Coach

Conference Speaker

Based in Gothenburg, Sweden

Author of

“The Coding Dojo Handbook”

@emilybache

[email protected]

Page 3: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Page 4: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Page 5: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Poll

Do you like writing tests?

On a scale of 1-5 how much do you enjoy the following coding activities?

● Coding a new function from scratch without writing any tests

● Coding a new function from scratch using Test-Driven Development

● Writing tests for an existing (poorly designed) function

● Refactoring an existing (poorly designed) function that lacks tests

● Refactoring an existing (poorly designed) function that has good tests

Page 6: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

DemoSupermarket Receipt

with Approval Testing

https://github.com/emilybache/SupermarketReceipt-Refactoring-Kata

Page 7: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Approval Testing Characteristics

Think and Write Activity

First impressions of Approval

Testing

● Think about what you just saw. If you had to explain the main idea to someone else, what would you say?

● Note down your explanation in a sentence or two.

Page 8: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Approval Testing Characteristics

Page 9: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Is designed by a humanRuns without intervention

Reports either ‘pass’ or ‘fail’

A Unit is a Small Piece of code

A method or functionA module or class

A group of related classes

An Automated Unit Test

@emilybache

Unit Testing Fundamentals

Page 10: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Exercise the unit under test

The Three Parts of a (Unit) Test

Arrange Act Assert

Set up the object to be tested, and collaborators

Make claims about what happened

Page 11: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Compare with Approved output

Three parts of an Approval Test

Arrange Act

@emilybache

Page 12: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

You inspect and approve actual program output when you

create a test case

Compare with Approved Output

Approved Actual

Page 13: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Compare with Approved output

Approval Tests should be reliable

Arrange Test Data,Fake time,

Stub network ...

Act

Page 14: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Compare with Approved output

Three/Four parts of an Approval Test

Arrange Act Print

Page 15: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Design a reusable Printer for Complex Objects

PRINTER

Or use a standard library to:● Serialize● Pickle● toString● toJson

Page 16: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Store Approved output with test sourcecode

SomeTestCase.java SomeTestCase.approved.txt

Put them in the same VCS repository

Page 17: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Refactoring Katas

Page 18: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

● Valuable code that works● Developers find it difficult● We need to change it safely

Legacy Code

Page 19: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

● Practice handling Legacy code

Refactoring Kata

Page 20: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Extract a unit to test

● Smaller pieces will have fewer behaviours

● May be bigger pieces than ordinary unit tests

Page 21: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache Image attribution: Icons8, http://icons8.com/

● Go through everything that’s in there

● Find suitable test data

Cover it in test cases

Page 22: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

● Improve the design● Make it easy to add the new

feature

Image attribution: Icons8, http://icons8.com/

Refactor

Page 23: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Find seams and create a unit

Cover with tests

@emilybache

Form of a Refactoring Kata

Refactor and add new

functionality

Page 24: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

DemoProduct Export

with Approval Testing

https://github.com/emilybache/Product-Export-Refactoring-Kata

Page 25: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache Image attribution: Icons8, http://icons8.com/

● Go through everything that’s in there

Use Approval Testing to Cover it in test cases

Page 26: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Approval Testing Legacy Code

We assume the code works

approve whatever the code does Add more cases

to increase coverage

Page 27: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Pre-Comparison Processing

Page 28: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Printers

PRINTER

● verifyXML()● verifyJSON()

Page 29: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Text-Based Approval Tests

Page 30: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Poll results

Do you like writing tests?

On a scale of 1-5 how much do you enjoy the following coding activities?

● Coding a new function from scratch without writing any tests

● Coding a new function from scratch using Test-Driven Development

● Writing tests for an existing (poorly designed) function

● Refactoring an existing (poorly designed) function that lacks tests

● Refactoring an existing (poorly designed) function that has good tests

Page 31: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

@emilybache

Page 33: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Approval Testing@emilybache

[email protected]

Legacy Code

Add Approval Tests to existing code Design the

output you approve

Diff-merge to view & update test results

Page 34: Approval Testing · “The Coding Dojo Handbook” ... enjoy the following coding activities? Coding a new function from scratch without writing any tests Coding a new function from

Spare Slides