SlideShare ist ein Scribd-Unternehmen logo
1 von 81
Downloaden Sie, um offline zu lesen
Donny Wals
@donnywals

https://donnywals.com

🎸 🎓 #
A Practical Approach to TDD in
the Workplace
–A developer who doesn’t write enough tests
“Yeah, I think this feature works.”
Today’s goals
• Understand how to build a quality test suite.

• Learn how to start testing in existing projects.

• Understand why a good test suite doesn’t cost (a lot of) extra
development time.
Before you write your tests
You must gather requirements
• Your stakeholders are pretty much anybody who can and will talk to you
about product requirements

• Don’t expect your stakeholders to give your their requirements clear and
concise

• Try to understand the wants and needs of your stakeholders rather than
taking whatever they say at face value

• Product owners and project managers should help you out
Talk to stakeholders
• Write down all requirements, these decisions are the foundation for your
tests

• For every business rule and requirement you determine, search edge
cases

• A language framework like Gherkin is helpful in this phase (more on
Gherkin later)
Formalize decisions
• Find out when the work is “done”

• Figure out the manual tests and workflows that stakeholders and testers
are going to run

• Refine your Gherkins
Establish acceptance criteria
• Do a final check to see if all cases are covered

• Check that errors are handled appropriately

• Make sure that all Gherkins are unambiguous
Review and refine
• Talk to stakeholders, understand their wants and needs

• Formalize decisions, write down business rules using Gherkin and find
edge cases

• Establish acceptation criteria, what “tests” will the stakeholder run
themselves once you deliver

• Review and refine
Gathering Requirements
Gherkin
A human readable language to define behavior
Feature
Provides a high level overview of a software feature,
and to group related scenarios.
Scenario
Brief description, used to provide context for the test
that it applies to.
Given
The initial state of the described test. Something that
has already happened or is ongoing.
When
The user input or system change that is tested. A
scenario should typically only be concerned with a
single action, earlier actions than the ones you care
about should either be given or part of the scenario.
Then
Describes the state of the system after it has been
manipulated by the action (When). Should only be
used to assert that the system is (eventually) in the
expected state.
What’s good about this
• Gherkin provides a solid foundation

• Leads to much better understanding of the system

• Much easier to discover missed cases and edge cases
Potential pitfalls
• Not always easy to get stakeholder buy-in

• Never assume that your Gherkins are complete

• Don’t take the definition phase to literally

• Stakeholders often don’t concern themselves with the deep internals of a
system
TDD
We’re close to seeing some actual tests, I promise
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
Repeat
STEP 4
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
Tested
• We can create an instance of
LoginForm

• LoginForm.login() throws

• LoginForm.username is
optional and nil by default

• LoginForm.password is
optional and nil by default
• LoginForm.login() does not
throw when username and
password are present

• LoginForm.login() throws a
different error when username
or password is missing

• We can set a username or
password on LoginForm

• And more…
Not tested
😍 TDD
• All the code you write is tested

• It provides a structured way to
think about a problem

• You can’t write untestable
code
• Can take a lot of time

• You’re allowed to blame the
Swift compiler for that

• It feels silly to knowingly write
tests that can’t pass for trivial
things

• It can feel somewhat limiting
when you just start out
😒 TDD
The way I like to do TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
A Quick Primer on TDD
A Failing Test
STEP 1
Write the minimal amount of code
needed to make the test pass
STEP 2
A Passing Test
STEP 3
Repeat
STEP 4
Tested
• We can create an instance of
LoginForm

• LoginForm.login() throws

• LoginForm.username is
optional and nil by default

• LoginForm.password is
optional and nil by default
• LoginForm.login() does not
throw when username and
password are present

• LoginForm.login() throws a
different error when username
or password is missing

• We can set a username or
password on LoginForm

• And more…
Not tested
To Xcode
It’s time to write some tests
File -> new -> Unit Test File
XCTest
• Xcode’s default testing framework

• Methods with the test prefix are your tests

• Doesn’t lend itself to a Gherkin style of testing very well
Quick
• A Behavior Driven Development testing framework

• Different keywords to highlight different parts of your tests

• Is very suitable for Gherkin style testing
Describe
Quick: Can be used to describe the system that’s
being tested.

TDD: Can be used the define the Given
Context
Quick: Can be used to describe the environment that
a system exists in

TDD: Can be used to define the When (the action)
It
Quick: Used to group and do assertions, the “actual”
test

TDD: Used to define the Then and do assertions
Important
• Quick was not really meant to be used as I just demonstrated

• Nevertheless, this works for me
Let’s implement a test!
Step 1 - Create login form
Step 2 - Perform action
Step 3 - Assert results
Remember the XCTest version?
Testing existing code
AKA the big refactor
Phase one: Preparation
• You can’t build an amazing test suite overnight

• You can, however, begin refactoring your code

• And of course, write tests for any new features
Phase one: Preparation
Before
Phase one: Preparation
After
Phase one: Preparation
After
LoginService
Abstracts the networking logic using a protocol so it
can be mocked in a test.
Phase two: Start small
• There’s no point in trying to test everything all at once

• Avoid complex tests at first, you might want to practice with simple tests
Phase two: Start small
Phase two: Start small
MockLoginService
A simple object that tracks whether its login method
was called
Phase two: Start small
Async assertion
We assume that the login method does asynchronous
work, the network call must eventually be made.
Phase three: Scale up
• Tackle more complex problems

• Expand your test cases

• Start thinking about integration tests
Getting time to test
Convincing your manager
Let’s look at a login flow
Inputs to test for email
• me@donnywals.com

• donny.wals@donnywals.com

• me@donnywals.co.uk

• invalid.com

• invalid@mail

• v.a.l.i.d@mail.com

• $1gnz@test.com

• And more…
And you need to do this on
every screen
Inputs to test for registration
• First name: Donny, Last name: Wals

• First name: Donny, Last name: van Wals

• First name: The Donny, Last name: Wals

• First name: D.onny, Last name: Wals

• First name: Bobby, Last name: Tables

• And many more…
How long would it take you to
test this?
Video
Taking it to the next level
Extra credit!
Xcode 11’s test plans
• Test localizations (mostly for UI)

• Run tests with different configurations

• Randomize test order
Run your tests on CI
• Running tests on every push to GitHub

• Automated testing on set intervals

• CI is the best way to make sure your tests are run
Summary
• Gathering requirements is vital to a good test suite

• Gherkin is a nice way to convert requirements to pseudo-tests

• Quick can be used to write very readable tests

• Begin refactoring a code base first, then slowly build up test coverage and
complexity

• Testing manually takes way more time than doing so automatically
Thank you
Questions, compliments and feedback are welcome

Weitere ähnliche Inhalte

Was ist angesagt?

TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in PracticeSteven Mak
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSDerek Lee Boire
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentMireia Sangalo
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOSPablo Villar
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Developmentsatya sudheer
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)Alan Dean
 
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzieHey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzieQA or the Highway
 
Finding a good development partner
Finding a good development partnerFinding a good development partner
Finding a good development partnerKevin Poorman
 
Tdd practices
Tdd practicesTdd practices
Tdd practicesaxykim00
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?Steven Mak
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 

Was ist angesagt? (20)

TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
ATDD in Practice
ATDD in PracticeATDD in Practice
ATDD in Practice
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOS
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzieHey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
 
Finding a good development partner
Finding a good development partnerFinding a good development partner
Finding a good development partner
 
TDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and JasmineTDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and Jasmine
 
TDD and BDD and ATDD
TDD and BDD and ATDDTDD and BDD and ATDD
TDD and BDD and ATDD
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Tdd
TddTdd
Tdd
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 

Ähnlich wie Adopting tdd in the workplace

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
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 1Blue Elephant Consulting
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
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 developmentEinar Ingebrigtsen
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development Amir Assad
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipCamille Bell
 
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 PerspectiveMalinda Kapuruge
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDDArati Joshi
 
An Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven DevelopmentAn Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven DevelopmentBlue Elephant Consulting
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascriptMichael Yagudaev
 
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 ShaonCefalo
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 

Ähnlich wie Adopting tdd in the workplace (20)

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Intro to TDD
Intro to TDDIntro to TDD
Intro to TDD
 
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
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
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
 
Test-Driven Development
 Test-Driven Development  Test-Driven Development
Test-Driven Development
 
Kata Your Way to SW Craftsmanship
Kata Your Way to SW CraftsmanshipKata Your Way to SW Craftsmanship
Kata Your Way to SW Craftsmanship
 
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
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
An Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven DevelopmentAn Introduction To Software Development - Test Driven Development
An Introduction To Software Development - Test Driven Development
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascript
 
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
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 

Mehr von Donny Wals

Your 🧠 on Swift Concurrency
Your 🧠 on Swift ConcurrencyYour 🧠 on Swift Concurrency
Your 🧠 on Swift ConcurrencyDonny Wals
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Donny Wals
 
The combine triad
The combine triadThe combine triad
The combine triadDonny Wals
 
Building reusable components with generics and protocols
Building reusable components with generics and protocolsBuilding reusable components with generics and protocols
Building reusable components with generics and protocolsDonny Wals
 
The Testing Games: Mocking, yay!
The Testing Games: Mocking, yay!The Testing Games: Mocking, yay!
The Testing Games: Mocking, yay!Donny Wals
 
Me and my importers
Me and my importersMe and my importers
Me and my importersDonny Wals
 
JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightDonny Wals
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
In Defense Of Core Data
In Defense Of Core DataIn Defense Of Core Data
In Defense Of Core DataDonny Wals
 
Effectively Producing And Shipping Frameworks For Multiple Platforms
Effectively Producing And Shipping Frameworks For Multiple PlatformsEffectively Producing And Shipping Frameworks For Multiple Platforms
Effectively Producing And Shipping Frameworks For Multiple PlatformsDonny Wals
 
Improving apps with iOS 10 notifications (do iOS 2016)
Improving apps with iOS 10 notifications (do iOS 2016)Improving apps with iOS 10 notifications (do iOS 2016)
Improving apps with iOS 10 notifications (do iOS 2016)Donny Wals
 
Talk - git task managers and ci
Talk - git task managers and ciTalk - git task managers and ci
Talk - git task managers and ciDonny Wals
 
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...Donny Wals
 
Marketing strategie Arto
Marketing strategie ArtoMarketing strategie Arto
Marketing strategie ArtoDonny Wals
 
Hoorcollege Flash 9-2-2012
Hoorcollege Flash 9-2-2012Hoorcollege Flash 9-2-2012
Hoorcollege Flash 9-2-2012Donny Wals
 

Mehr von Donny Wals (15)

Your 🧠 on Swift Concurrency
Your 🧠 on Swift ConcurrencyYour 🧠 on Swift Concurrency
Your 🧠 on Swift Concurrency
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
 
The combine triad
The combine triadThe combine triad
The combine triad
 
Building reusable components with generics and protocols
Building reusable components with generics and protocolsBuilding reusable components with generics and protocols
Building reusable components with generics and protocols
 
The Testing Games: Mocking, yay!
The Testing Games: Mocking, yay!The Testing Games: Mocking, yay!
The Testing Games: Mocking, yay!
 
Me and my importers
Me and my importersMe and my importers
Me and my importers
 
JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than Twilight
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
In Defense Of Core Data
In Defense Of Core DataIn Defense Of Core Data
In Defense Of Core Data
 
Effectively Producing And Shipping Frameworks For Multiple Platforms
Effectively Producing And Shipping Frameworks For Multiple PlatformsEffectively Producing And Shipping Frameworks For Multiple Platforms
Effectively Producing And Shipping Frameworks For Multiple Platforms
 
Improving apps with iOS 10 notifications (do iOS 2016)
Improving apps with iOS 10 notifications (do iOS 2016)Improving apps with iOS 10 notifications (do iOS 2016)
Improving apps with iOS 10 notifications (do iOS 2016)
 
Talk - git task managers and ci
Talk - git task managers and ciTalk - git task managers and ci
Talk - git task managers and ci
 
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...
Developing in the Fastlane -> How LookLive uses Fastlane to automate and spee...
 
Marketing strategie Arto
Marketing strategie ArtoMarketing strategie Arto
Marketing strategie Arto
 
Hoorcollege Flash 9-2-2012
Hoorcollege Flash 9-2-2012Hoorcollege Flash 9-2-2012
Hoorcollege Flash 9-2-2012
 

Kürzlich hochgeladen

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 

Kürzlich hochgeladen (20)

Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 

Adopting tdd in the workplace

  • 2. A Practical Approach to TDD in the Workplace
  • 3. –A developer who doesn’t write enough tests “Yeah, I think this feature works.”
  • 4. Today’s goals • Understand how to build a quality test suite. • Learn how to start testing in existing projects. • Understand why a good test suite doesn’t cost (a lot of) extra development time.
  • 5. Before you write your tests You must gather requirements
  • 6. • Your stakeholders are pretty much anybody who can and will talk to you about product requirements • Don’t expect your stakeholders to give your their requirements clear and concise • Try to understand the wants and needs of your stakeholders rather than taking whatever they say at face value • Product owners and project managers should help you out Talk to stakeholders
  • 7. • Write down all requirements, these decisions are the foundation for your tests • For every business rule and requirement you determine, search edge cases • A language framework like Gherkin is helpful in this phase (more on Gherkin later) Formalize decisions
  • 8. • Find out when the work is “done” • Figure out the manual tests and workflows that stakeholders and testers are going to run • Refine your Gherkins Establish acceptance criteria
  • 9. • Do a final check to see if all cases are covered • Check that errors are handled appropriately • Make sure that all Gherkins are unambiguous Review and refine
  • 10. • Talk to stakeholders, understand their wants and needs • Formalize decisions, write down business rules using Gherkin and find edge cases • Establish acceptation criteria, what “tests” will the stakeholder run themselves once you deliver • Review and refine Gathering Requirements
  • 11. Gherkin A human readable language to define behavior
  • 12.
  • 13. Feature Provides a high level overview of a software feature, and to group related scenarios.
  • 14. Scenario Brief description, used to provide context for the test that it applies to.
  • 15. Given The initial state of the described test. Something that has already happened or is ongoing.
  • 16. When The user input or system change that is tested. A scenario should typically only be concerned with a single action, earlier actions than the ones you care about should either be given or part of the scenario.
  • 17. Then Describes the state of the system after it has been manipulated by the action (When). Should only be used to assert that the system is (eventually) in the expected state.
  • 18. What’s good about this • Gherkin provides a solid foundation • Leads to much better understanding of the system • Much easier to discover missed cases and edge cases
  • 19. Potential pitfalls • Not always easy to get stakeholder buy-in • Never assume that your Gherkins are complete • Don’t take the definition phase to literally • Stakeholders often don’t concern themselves with the deep internals of a system
  • 20. TDD We’re close to seeing some actual tests, I promise
  • 21. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 22. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 23. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 24. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 25. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 26. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 27. A Quick Primer on TDD Repeat STEP 4 A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 28. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 29. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 30. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 31. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 32. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 33. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 34. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 35. Tested • We can create an instance of LoginForm • LoginForm.login() throws • LoginForm.username is optional and nil by default • LoginForm.password is optional and nil by default • LoginForm.login() does not throw when username and password are present • LoginForm.login() throws a different error when username or password is missing • We can set a username or password on LoginForm • And more… Not tested
  • 36. 😍 TDD • All the code you write is tested • It provides a structured way to think about a problem • You can’t write untestable code • Can take a lot of time • You’re allowed to blame the Swift compiler for that • It feels silly to knowingly write tests that can’t pass for trivial things • It can feel somewhat limiting when you just start out 😒 TDD
  • 37. The way I like to do TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 38. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 39. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 40. A Quick Primer on TDD A Failing Test STEP 1 Write the minimal amount of code needed to make the test pass STEP 2 A Passing Test STEP 3 Repeat STEP 4
  • 41. Tested • We can create an instance of LoginForm • LoginForm.login() throws • LoginForm.username is optional and nil by default • LoginForm.password is optional and nil by default • LoginForm.login() does not throw when username and password are present • LoginForm.login() throws a different error when username or password is missing • We can set a username or password on LoginForm • And more… Not tested
  • 42. To Xcode It’s time to write some tests
  • 43. File -> new -> Unit Test File
  • 44.
  • 45. XCTest • Xcode’s default testing framework • Methods with the test prefix are your tests • Doesn’t lend itself to a Gherkin style of testing very well
  • 46.
  • 47. Quick • A Behavior Driven Development testing framework • Different keywords to highlight different parts of your tests • Is very suitable for Gherkin style testing
  • 48. Describe Quick: Can be used to describe the system that’s being tested. TDD: Can be used the define the Given
  • 49. Context Quick: Can be used to describe the environment that a system exists in TDD: Can be used to define the When (the action)
  • 50. It Quick: Used to group and do assertions, the “actual” test TDD: Used to define the Then and do assertions
  • 51. Important • Quick was not really meant to be used as I just demonstrated • Nevertheless, this works for me
  • 53. Step 1 - Create login form
  • 54. Step 2 - Perform action
  • 55. Step 3 - Assert results
  • 57.
  • 58.
  • 59. Testing existing code AKA the big refactor
  • 60. Phase one: Preparation • You can’t build an amazing test suite overnight • You can, however, begin refactoring your code • And of course, write tests for any new features
  • 63. Phase one: Preparation After LoginService Abstracts the networking logic using a protocol so it can be mocked in a test.
  • 64. Phase two: Start small • There’s no point in trying to test everything all at once • Avoid complex tests at first, you might want to practice with simple tests
  • 66. Phase two: Start small MockLoginService A simple object that tracks whether its login method was called
  • 67. Phase two: Start small Async assertion We assume that the login method does asynchronous work, the network call must eventually be made.
  • 68. Phase three: Scale up • Tackle more complex problems • Expand your test cases • Start thinking about integration tests
  • 69. Getting time to test Convincing your manager
  • 70. Let’s look at a login flow
  • 71.
  • 72. Inputs to test for email • me@donnywals.com • donny.wals@donnywals.com • me@donnywals.co.uk • invalid.com • invalid@mail • v.a.l.i.d@mail.com • $1gnz@test.com • And more…
  • 73. And you need to do this on every screen
  • 74. Inputs to test for registration • First name: Donny, Last name: Wals • First name: Donny, Last name: van Wals • First name: The Donny, Last name: Wals • First name: D.onny, Last name: Wals • First name: Bobby, Last name: Tables • And many more…
  • 75. How long would it take you to test this?
  • 76. Video
  • 77. Taking it to the next level Extra credit!
  • 78. Xcode 11’s test plans • Test localizations (mostly for UI) • Run tests with different configurations • Randomize test order
  • 79. Run your tests on CI • Running tests on every push to GitHub • Automated testing on set intervals • CI is the best way to make sure your tests are run
  • 80. Summary • Gathering requirements is vital to a good test suite • Gherkin is a nice way to convert requirements to pseudo-tests • Quick can be used to write very readable tests • Begin refactoring a code base first, then slowly build up test coverage and complexity • Testing manually takes way more time than doing so automatically
  • 81. Thank you Questions, compliments and feedback are welcome