SlideShare a Scribd company logo
Test Driven Development
Malinda Kapuruge
@kaushalye
Guest lecture @ Swinburne University of Technology, Melbourne
a Practitioner’s Perspective
01 / 05 / 2019
Outline
• Software development
• Software testing
• TDD
• Demo
• Few other topics
• Questions (Interrupt me anytime)
Software
Development
Users
Code
Development team
ApplicationBusiness
Features / Issues Deploy
Commit
Access
Software
Testing
Source : NIST - National Institute of Standards and Technology
Software Testing
Functional
Unit testing
smallest
testable unit
Integration
testing
Interactions
btwn modules
Regression
testing
In-depth
analysis on
functionalities
Smoke testing
A set of test to
quickly check
basic
functionalities
...
Non-functional
Load testing Stress testing
Security
testing
Reliability
testing
..,
E2E
Integration
Unit
FasterSlower
LessIntegratedHeavilyintegrated
Unit Tests
• Unit of code,
e.g., a function
• Smallest testable piece
• Assertions
• Data
• Quick to run (short feedback loop)
• Isolation (No connection to DBs or other services)
Test Driven
Development
TDD
TDD != Writing unit tests
Application Tests
Tests Application
Write a test for
something that
doesn’t exist yet ?
Add test /
refactor
Fix
Run test
Fail
• Start with a failing test
• Make test pass
• Write more tests
• Make the pass … cont.
• Refactoring is part of the process
• Red-green-refactor
Pass
Tests
TDD Benefits
• Better designed code
• The interaction with other parts of code is already understood
• Better understood business requirements
• Tests are sort of a well-defined specification*
• Improved code quality
• Minimum code required to make the test pass
• Confidence to refactor code
• E.g., a programmer new to the team.
• Evolutionary technique
• Small steps towards end goal. Few lines of code at a time.
• Detect bugs early
• Assertions are already there
• Efficient and less costly
Feedback loop is minutes.
Source http://www.agilemodeling.com/essays/costOfChange.htm
SLIDES !
Demo ?
Demo time!
• NodeJS – development platform
• https://nodejs.org/en/download/
• Jest – Test tool
• https://jestjs.io/
A function to check for strong passwords ...
What happened ?
• We did NOT start with the implementation
• We postponed answering the question “HOW?”
• We focused on expectations
• We clarified the requirements / specification
• We understood the inputs and outputs
• We started with the simplest form of the function, i.e., smallest step
• We observed failing tests
• We did small increments until the function is satisfactory
• We detect bugs early in the implementation
We ended up
with
A good test coverage
Minimal amount of code
Code satisfies current business
expectations / assertions
Assertions are captured as a test
specification
Tools that can help us
Test tools Development language / platform
JSUnit, Jasmine, Tape, Jest, Mocha, Chai, Sinon Node
Junit, Mockito, TestNG Java
PyUnit, Nose, pytest Python
Go test Go
Rspec, Test::Unit (builtin) Ruby
PHPUnit PHP
Cppunit, Google test, Boost C++
* These tools are OPTIONAL. But can make it easier to write and execute tests
Practical TDD
• TDD Zealots – do this or you are wrong
• Sometimes the first test doesn’t come naturally
• Playing with code and other components/services first
• Tests are good as long as all relevant assertions are covered.
• ATDD
• Passing tests vs Validness of solution (cheating)
• Bad unit tests -> bad TDD
• TDD - needs some practice
• Measure test coverage
Microservices and
TDD
Microservices
• Is an architecture style
• Loosely coupled services
• A service represents a specific business function
• Invoice service
• Customer service
• Payment service
• Separately deployed in different runtimes
• Highly maintainable, scalable and testable
runtime
Microservices and TDD
• Different runtimes and tech stacks
• Service – service interactions
• Mocks
• Version control
Runtime
Customer
Object
Invoice
Object
runtime
Customer
Service
Invoice
Service
Microservices and TDD
• Integration tests can be used to test the validity of service-service
interactions
• But TDD needs unit tests (short feedback loop)
Microservices and TDD
• Service contracts
• Pact framework
• A contract testing tool
• Consumer-driven
• Pact tests are unit tests
• TDD
Pact broker
Pact file
( version controlled )
Customer
Service
Invoice
Service
Unit
tests
Consumer
Provider
Example:
Frontend dev and
TDD
TDD for frontend
• Traditional frontend development
• Modern frameworks, come with all the goodies to start TDD
• e.g., react, angular,
• TDD for services and models
• E.g,, Enzyme
• TDD for UI/Visualization ???
• Can be done… but…
What is BDD ?
Behaviour-Driven Development
• Flavor that can be used to write unit tests
• Provide a structure
• Given, when, then format , e.g.,
Given('The user is authorised', function() {});
When('The user requests invoice data', function() {});
Then(‘Correct invoices are returned', function() {});
• Technical as well as non-technical users
• TDD and BDD complements each other
• Many tools, e.g., Cucumber, JBehave, RSpec.
Summary
• TDD is a software development methodology
• Start with failing tests, refactor until test pass.
Continue…
• Business requirements are captured as tests
• Many benefits
• Many tools
• Challenges in architectures like microservices
• To TDD or not to TDD? Case by case.
Questions ???
Further reading
• Test-Driven Development by Example – Kent Beck
• http://agiledata.org/essays/tdd.html
• https://www.agilealliance.org

More Related Content

PPTX
Continuous Integration: Finding problems soonest
PPTX
Presentation delex
PPTX
Benefits from AATs
PDF
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
PDF
Test-driven development with Node.js
PPTX
Continuous everything
PPTX
Unit Testing and Tools - ADNUG
PPTX
Unit Testing and Tools
Continuous Integration: Finding problems soonest
Presentation delex
Benefits from AATs
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Test-driven development with Node.js
Continuous everything
Unit Testing and Tools - ADNUG
Unit Testing and Tools

What's hot (20)

PPTX
TDD Basics with Angular.js and Jasmine
PDF
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
PPT
TDD In Practice
PDF
What is this agile thing anyway
PPTX
Unit Testing talk
PPTX
Making a Mock by Kelsey Shannahan
PPTX
Power-Up Your Test Suite with OLE Automation by Joshua Russell
PDF
Improving Test Team Throughput via Architecture by Dustin Williams
PDF
АННА ТИМОФІЄВА & СЕРГІЙ МАЛИНОВСЬКИЙ «Tools and Tips of video connection test...
PDF
Design for Testability in Practice
PDF
NYC MeetUp 10.9
PPTX
Elements of a Test Framework
PPTX
Selenium + Specflow
PDF
2020-Feb: Testing: Cables and Chains
PPTX
Writing better tests for your java script app
PPTX
Avoiding test hell
PPTX
Implementing Test Automation in Agile Projects
PPTX
DDT Testing Library for Android
PPTX
Automated Testing with Logic Apps and Specflow
PPTX
Beginners overview of automated testing with Rspec
TDD Basics with Angular.js and Jasmine
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
TDD In Practice
What is this agile thing anyway
Unit Testing talk
Making a Mock by Kelsey Shannahan
Power-Up Your Test Suite with OLE Automation by Joshua Russell
Improving Test Team Throughput via Architecture by Dustin Williams
АННА ТИМОФІЄВА & СЕРГІЙ МАЛИНОВСЬКИЙ «Tools and Tips of video connection test...
Design for Testability in Practice
NYC MeetUp 10.9
Elements of a Test Framework
Selenium + Specflow
2020-Feb: Testing: Cables and Chains
Writing better tests for your java script app
Avoiding test hell
Implementing Test Automation in Agile Projects
DDT Testing Library for Android
Automated Testing with Logic Apps and Specflow
Beginners overview of automated testing with Rspec
Ad

Similar to Test Driven Development - a Practitioner’s Perspective (20)

PPTX
Understanding TDD - theory, practice, techniques and tips.
PPTX
TDD - Seriously, try it! - Opensouthcode
PDF
An Introduction to Test Driven Development
PPTX
TDD - Seriously, try it - Codemotion (May '24)
PPTX
TDD - Seriously, try it! (updated '22)
PPTX
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
PPTX
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
PPTX
TDD - Seriously, try it! - Bucarest Tech Week
PPTX
Test-Driven Development.pptx
PPTX
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
KEY
TDD refresher
PPTX
Anatomy of Test Driven Development
PPTX
Test driven development(tdd)
PPTX
Test driven development v1.0
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PPT
Test Driven Development using QUnit
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
PPTX
TDD Training
PPTX
Test-driven development & Behavior-driven development basics
Understanding TDD - theory, practice, techniques and tips.
TDD - Seriously, try it! - Opensouthcode
An Introduction to Test Driven Development
TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Bucarest Tech Week
Test-Driven Development.pptx
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
TDD refresher
Anatomy of Test Driven Development
Test driven development(tdd)
Test driven development v1.0
Intro To JavaScript Unit Testing - Ran Mizrahi
Test Driven Development using QUnit
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
TDD Training
Test-driven development & Behavior-driven development basics
Ad

More from Malinda Kapuruge (13)

PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
PDF
Moving faster with CI/CD: Best DevOps practices and lessons learnt
PDF
Be DevOps Ready
PPTX
Technical guidance in SaaS Startups
PDF
Devops - why, what and how?
PDF
SaaS startups - Software Engineering Challenges
PPTX
Life after PhD - An insight and a few tips to kick-start your career in the i...
PPTX
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
PDF
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
PPTX
Supporting Adaptation Patterns in the Event-driven Business Process Modell...
PPTX
Scalable, Business Service-based SaaS Applications
PPTX
Representing Service-Relationships as First Class Entities in Service Orchest...
PPTX
Achieving Multi-tenanted Business Processes in SaaS Applications
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Moving faster with CI/CD: Best DevOps practices and lessons learnt
Be DevOps Ready
Technical guidance in SaaS Startups
Devops - why, what and how?
SaaS startups - Software Engineering Challenges
Life after PhD - An insight and a few tips to kick-start your career in the i...
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Supporting Adaptation Patterns in the Event-driven Business Process Modell...
Scalable, Business Service-based SaaS Applications
Representing Service-Relationships as First Class Entities in Service Orchest...
Achieving Multi-tenanted Business Processes in SaaS Applications

Recently uploaded (20)

PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
L1 - Introduction to python Backend.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Digital Strategies for Manufacturing Companies
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
PTS Company Brochure 2025 (1).pdf.......
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms I-SECS-1021-03
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
L1 - Introduction to python Backend.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Digital Strategies for Manufacturing Companies
wealthsignaloriginal-com-DS-text-... (1).pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
CHAPTER 2 - PM Management and IT Context
PTS Company Brochure 2025 (1).pdf.......

Test Driven Development - a Practitioner’s Perspective

  • 1. Test Driven Development Malinda Kapuruge @kaushalye Guest lecture @ Swinburne University of Technology, Melbourne a Practitioner’s Perspective 01 / 05 / 2019
  • 2. Outline • Software development • Software testing • TDD • Demo • Few other topics • Questions (Interrupt me anytime)
  • 6. Source : NIST - National Institute of Standards and Technology
  • 7. Software Testing Functional Unit testing smallest testable unit Integration testing Interactions btwn modules Regression testing In-depth analysis on functionalities Smoke testing A set of test to quickly check basic functionalities ... Non-functional Load testing Stress testing Security testing Reliability testing ..,
  • 9. Unit Tests • Unit of code, e.g., a function • Smallest testable piece • Assertions • Data • Quick to run (short feedback loop) • Isolation (No connection to DBs or other services)
  • 11. TDD != Writing unit tests Application Tests Tests Application
  • 12. Write a test for something that doesn’t exist yet ?
  • 13. Add test / refactor Fix Run test Fail • Start with a failing test • Make test pass • Write more tests • Make the pass … cont. • Refactoring is part of the process • Red-green-refactor Pass
  • 14. Tests
  • 15. TDD Benefits • Better designed code • The interaction with other parts of code is already understood • Better understood business requirements • Tests are sort of a well-defined specification* • Improved code quality • Minimum code required to make the test pass • Confidence to refactor code • E.g., a programmer new to the team. • Evolutionary technique • Small steps towards end goal. Few lines of code at a time. • Detect bugs early • Assertions are already there • Efficient and less costly
  • 16. Feedback loop is minutes. Source http://www.agilemodeling.com/essays/costOfChange.htm
  • 18. Demo time! • NodeJS – development platform • https://nodejs.org/en/download/ • Jest – Test tool • https://jestjs.io/ A function to check for strong passwords ...
  • 19. What happened ? • We did NOT start with the implementation • We postponed answering the question “HOW?” • We focused on expectations • We clarified the requirements / specification • We understood the inputs and outputs • We started with the simplest form of the function, i.e., smallest step • We observed failing tests • We did small increments until the function is satisfactory • We detect bugs early in the implementation
  • 20. We ended up with A good test coverage Minimal amount of code Code satisfies current business expectations / assertions Assertions are captured as a test specification
  • 21. Tools that can help us Test tools Development language / platform JSUnit, Jasmine, Tape, Jest, Mocha, Chai, Sinon Node Junit, Mockito, TestNG Java PyUnit, Nose, pytest Python Go test Go Rspec, Test::Unit (builtin) Ruby PHPUnit PHP Cppunit, Google test, Boost C++ * These tools are OPTIONAL. But can make it easier to write and execute tests
  • 22. Practical TDD • TDD Zealots – do this or you are wrong • Sometimes the first test doesn’t come naturally • Playing with code and other components/services first • Tests are good as long as all relevant assertions are covered. • ATDD • Passing tests vs Validness of solution (cheating) • Bad unit tests -> bad TDD • TDD - needs some practice • Measure test coverage
  • 24. Microservices • Is an architecture style • Loosely coupled services • A service represents a specific business function • Invoice service • Customer service • Payment service • Separately deployed in different runtimes • Highly maintainable, scalable and testable
  • 25. runtime Microservices and TDD • Different runtimes and tech stacks • Service – service interactions • Mocks • Version control Runtime Customer Object Invoice Object runtime Customer Service Invoice Service
  • 26. Microservices and TDD • Integration tests can be used to test the validity of service-service interactions • But TDD needs unit tests (short feedback loop)
  • 27. Microservices and TDD • Service contracts • Pact framework • A contract testing tool • Consumer-driven • Pact tests are unit tests • TDD Pact broker Pact file ( version controlled ) Customer Service Invoice Service Unit tests Consumer Provider
  • 30. TDD for frontend • Traditional frontend development • Modern frameworks, come with all the goodies to start TDD • e.g., react, angular, • TDD for services and models • E.g,, Enzyme • TDD for UI/Visualization ??? • Can be done… but…
  • 32. Behaviour-Driven Development • Flavor that can be used to write unit tests • Provide a structure • Given, when, then format , e.g., Given('The user is authorised', function() {}); When('The user requests invoice data', function() {}); Then(‘Correct invoices are returned', function() {}); • Technical as well as non-technical users • TDD and BDD complements each other • Many tools, e.g., Cucumber, JBehave, RSpec.
  • 33. Summary • TDD is a software development methodology • Start with failing tests, refactor until test pass. Continue… • Business requirements are captured as tests • Many benefits • Many tools • Challenges in architectures like microservices • To TDD or not to TDD? Case by case.
  • 35. Further reading • Test-Driven Development by Example – Kent Beck • http://agiledata.org/essays/tdd.html • https://www.agilealliance.org

Editor's Notes