SlideShare uma empresa Scribd logo
1 de 40
Understanding TDD
Malinda Kapuruge
@kaushalye
Guest lecture @ Swinburne University of Technology, Melbourne 09 / 10 / 2019
theory, practice, techniques and tips…!
You will learn
• Software testing - overview
• TDD vs Writing unit tests
• TDD in action - Demo
• Few techniques, tools and tips
• Time for question / discussions
(feel free to interrupt any time)
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 external state)
Test Driven Development
TDD
TDD != Writing unit tests
Application Tests
Tests Application
Testing
something that
doesn’t exist ?
Add test /
refactor
Fix
Run test
Fail
• Start with a failing test
• Make test pass
• Write more tests
• Make test pass … cont.
• Refactoring is part of the process
• Red-green-refactor
Pass
First test round - always FAIL !
( if passed then we have a bigger problem to deal with :D )
Minimal code required to PASS the tests.
No speculative code.
TDD vs Writing testsTest Driven Development
A software development process
Upfront design thinking
Tests come first
More about software design than
testing
Writing unit tests
A way to ensure code works
An after thought to confirm
assertions
Tests come second
More about testing than software
design
Knowing how to write better unit tests is crucial to TDD
Vs
Feedback loop is minutes.
Source http://www.agilemodeling.com/essays/costOfChange.htm
TDD Benefits
Better designed code
• The interactions are already understood
Clear business requirements
• Tests act as a well-defined specification
Improved code quality
• Minimum code required to make the test pass
Focus
• Narrow focus. High productivity.
Confidence to refactor
• Touching the code after few weeks, new team members etc.
Evolutionary technique
• Small steps towards end goal. Few lines of code at a time.
Detect errors early in the process
• Assertions are already there
SLIDES !
Demo ?
Demo
• NodeJS – development platform
• https://nodejs.org/en/download/
• Jest – Test tool
• https://jestjs.io/
A function to check strong passwords ...
%mkdir password && cd $_
%git init
%npm init --yes
%npm i jest
%mkdir test
%touch test/password.test.js
f()input output
assertions
test("description", function);
e.g.,
test("test description", () => {
expect(1+2).toBe(3);
});
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
TDD – Criticisms and Practicality
• TDD Zealots – do this or you are wrong
• Reactance theory – freedom – teams - benefits
• Sometimes the first test doesn’t come naturally
• Playing with code and other components first
• Tests are good as long as all relevant assertions are covered.
• ATDD - Acceptance test–driven development
• Bad unit tests -> bad TDD
• Fast test execution
• TDD - needs practice
• Measure test coverage
Tools that can help us
Test tools Development language
JSUnit, Jasmine, Tape, Jest, Mocha, Chai, Sinon Node / Javascript
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
Isolating Dependencies
Dependencies
• HTTP calls, Database, File IO
• Inconsistent outcome of the test
• Network connectivity issues
• External state changes
• Time consuming, Error-prone
• CI/CD pipelines
• Stunt Test Doubles
• Cheaper than the real one ;-)
• E.g., Sinon :- Spy/Stub/Mock
Spy Stub Mock
Gather information about a
function call (spying).
A spy does not replace the
existing function.
e.g., to check if a function is
called
Replaces the existing function.
e.g., to remove external dependencies.
Replaces the whole object.
e.g., Handy to test more than one
function.
var callback = sinon.spy();
myFunction(true, callback);
sinon.assert(callback.calledOnce);
var post = sinon.stub($, 'post’);
post.yields();
myFunction(user, function(){} );
post.restore();
sinon.assert.calledWith(post, expectedUrl,
expectedParams);
var storeMock = sinon.mock(store);
storeMock.expects('get').withArgs('data').retu
rns(0);
storeMock.expects('set').once().withArgs('data
', 1);
myFunction();
storeMock.restore();
storeMock.verify();
TDD with Microservices
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
TDD with Microservices
• Different runtimes and tech stacks
• Service – service interactions
• Mocks
• Version control
Runtime
Customer
Object
Invoice
Object
runtime
Customer
Service
Invoice
Service
TDD with Microservices
• Integration tests can be used to test the validity of service-service
interactions
• But TDD needs unit tests (short feedback loop)
Pacts
• 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 -> a JavaScript Testing utility for React
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() {});
• Human readable - Technical and 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.
Further reading
• Test-Driven Development by Example – Kent Beck
• http://agiledata.org/essays/tdd.html
• https://www.agilealliance.org
Questions ???
Versant is hiring 
https://versent.workable.com/j/48ED01EAC5

Mais conteúdo relacionado

Mais procurados

Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL storeEdward Capriolo
 
Continuous Security in DevOps
Continuous Security in DevOpsContinuous Security in DevOps
Continuous Security in DevOpsMaciej Lasyk
 
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew Nelson
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew NelsonPerformance Tuning with Zabbix - Zabbix Conference 2014 - Andrew Nelson
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew NelsonAndrew Nelson
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfAndrew Lamb
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.Vlad Fedosov
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by AccidentGleicon Moraes
 
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Chris Gates
 
Appsec DC - wXf -2010
Appsec DC - wXf  -2010Appsec DC - wXf  -2010
Appsec DC - wXf -2010Chris Gates
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopVelocidex Enterprises
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmSkills Matter
 
Docker Security - Secure Container Deployment on Linux
Docker Security - Secure Container Deployment on LinuxDocker Security - Secure Container Deployment on Linux
Docker Security - Secure Container Deployment on LinuxMichael Boelen
 
First adventure within a shell - Andrea Telatin at Quadram Institute
First adventure within a shell - Andrea Telatin at Quadram InstituteFirst adventure within a shell - Andrea Telatin at Quadram Institute
First adventure within a shell - Andrea Telatin at Quadram InstituteAndrea Telatin
 
Buildr - build like you code
Buildr -  build like you codeBuildr -  build like you code
Buildr - build like you codeIzzet Mustafaiev
 
Securing Your MongoDB Deployment
Securing Your MongoDB DeploymentSecuring Your MongoDB Deployment
Securing Your MongoDB DeploymentMongoDB
 
Managing High Availability with Low Cost
Managing High Availability with Low CostManaging High Availability with Low Cost
Managing High Availability with Low CostDataLeader.io
 

Mais procurados (20)

Building your own NSQL store
Building your own NSQL storeBuilding your own NSQL store
Building your own NSQL store
 
Continuous Security in DevOps
Continuous Security in DevOpsContinuous Security in DevOps
Continuous Security in DevOps
 
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew Nelson
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew NelsonPerformance Tuning with Zabbix - Zabbix Conference 2014 - Andrew Nelson
Performance Tuning with Zabbix - Zabbix Conference 2014 - Andrew Nelson
 
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdfManaging Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.DevOps Fest 2020. immutable infrastructure as code. True story.
DevOps Fest 2020. immutable infrastructure as code. True story.
 
Node.js architecture (EN)
Node.js architecture (EN)Node.js architecture (EN)
Node.js architecture (EN)
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by Accident
 
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
 
Appsec DC - wXf -2010
Appsec DC - wXf  -2010Appsec DC - wXf  -2010
Appsec DC - wXf -2010
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Docker Security - Secure Container Deployment on Linux
Docker Security - Secure Container Deployment on LinuxDocker Security - Secure Container Deployment on Linux
Docker Security - Secure Container Deployment on Linux
 
Javascript
JavascriptJavascript
Javascript
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
First adventure within a shell - Andrea Telatin at Quadram Institute
First adventure within a shell - Andrea Telatin at Quadram InstituteFirst adventure within a shell - Andrea Telatin at Quadram Institute
First adventure within a shell - Andrea Telatin at Quadram Institute
 
Buildr - build like you code
Buildr -  build like you codeBuildr -  build like you code
Buildr - build like you code
 
Securing Your MongoDB Deployment
Securing Your MongoDB DeploymentSecuring Your MongoDB Deployment
Securing Your MongoDB Deployment
 
Managing High Availability with Low Cost
Managing High Availability with Low CostManaging High Availability with Low Cost
Managing High Availability with Low Cost
 

Semelhante a Understanding TDD - theory, practice, techniques and tips.

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
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
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
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnitsatejsahu
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Ortus Solutions, Corp
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Uma Ghotikar
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile DeveloperBSGAfrica
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentMike Douglas
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testingDuy Tan Geek
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-DrivenIan Truslove
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)Peter Kofler
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated TestingLars Thorup
 

Semelhante a Understanding TDD - theory, practice, techniques and tips. (20)

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
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
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
 
Agile testing
Agile testingAgile testing
Agile testing
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
 
Benefits from AATs
Benefits from AATsBenefits from AATs
Benefits from AATs
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 

Mais de Malinda Kapuruge

Life after PhD - An insight and a few tips to kick-start your career in the i...
Life after PhD - An insight and a few tips to kick-start your career in the i...Life after PhD - An insight and a few tips to kick-start your career in the i...
Life after PhD - An insight and a few tips to kick-start your career in the i...Malinda Kapuruge
 
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...Malinda Kapuruge
 
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Malinda Kapuruge
 
Supporting Adaptation Patterns in the Event-driven Business Process Modell...
Supporting  Adaptation Patterns  in the Event-driven  Business Process Modell...Supporting  Adaptation Patterns  in the Event-driven  Business Process Modell...
Supporting Adaptation Patterns in the Event-driven Business Process Modell...Malinda Kapuruge
 
Scalable, Business Service-based SaaS Applications
Scalable, Business Service-based SaaS ApplicationsScalable, Business Service-based SaaS Applications
Scalable, Business Service-based SaaS ApplicationsMalinda Kapuruge
 
Representing Service-Relationships as First Class Entities in Service Orchest...
Representing Service-Relationships as First Class Entities in Service Orchest...Representing Service-Relationships as First Class Entities in Service Orchest...
Representing Service-Relationships as First Class Entities in Service Orchest...Malinda Kapuruge
 
Achieving Multi-tenanted Business Processes in SaaS Applications
Achieving Multi-tenanted Business Processes in SaaS Applications  Achieving Multi-tenanted Business Processes in SaaS Applications
Achieving Multi-tenanted Business Processes in SaaS Applications Malinda Kapuruge
 

Mais de Malinda Kapuruge (8)

Be DevOps Ready
Be DevOps ReadyBe DevOps Ready
Be DevOps Ready
 
Life after PhD - An insight and a few tips to kick-start your career in the i...
Life after PhD - An insight and a few tips to kick-start your career in the i...Life after PhD - An insight and a few tips to kick-start your career in the i...
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 ...
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
EPClets - A Lightweight and Flexible Textual Language to Augment EPC Process ...
 
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
Enabling Ad-hoc Business Process Adaptations through Event-driven Task Decoup...
 
Supporting Adaptation Patterns in the Event-driven Business Process Modell...
Supporting  Adaptation Patterns  in the Event-driven  Business Process Modell...Supporting  Adaptation Patterns  in the Event-driven  Business Process Modell...
Supporting Adaptation Patterns in the Event-driven Business Process Modell...
 
Scalable, Business Service-based SaaS Applications
Scalable, Business Service-based SaaS ApplicationsScalable, Business Service-based SaaS Applications
Scalable, Business Service-based SaaS Applications
 
Representing Service-Relationships as First Class Entities in Service Orchest...
Representing Service-Relationships as First Class Entities in Service Orchest...Representing Service-Relationships as First Class Entities in Service Orchest...
Representing Service-Relationships as First Class Entities in Service Orchest...
 
Achieving Multi-tenanted Business Processes in SaaS Applications
Achieving Multi-tenanted Business Processes in SaaS Applications  Achieving Multi-tenanted Business Processes in SaaS Applications
Achieving Multi-tenanted Business Processes in SaaS Applications
 

Último

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
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
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
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
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
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
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
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
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
 
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
 

Último (20)

Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
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
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
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...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
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
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
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
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
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
 
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
 

Understanding TDD - theory, practice, techniques and tips.

  • 1. Understanding TDD Malinda Kapuruge @kaushalye Guest lecture @ Swinburne University of Technology, Melbourne 09 / 10 / 2019 theory, practice, techniques and tips…!
  • 2. You will learn • Software testing - overview • TDD vs Writing unit tests • TDD in action - Demo • Few techniques, tools and tips • Time for question / discussions (feel free to interrupt any time)
  • 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 external state)
  • 11. TDD != Writing unit tests Application Tests Tests Application
  • 13. Add test / refactor Fix Run test Fail • Start with a failing test • Make test pass • Write more tests • Make test pass … cont. • Refactoring is part of the process • Red-green-refactor Pass
  • 14. First test round - always FAIL ! ( if passed then we have a bigger problem to deal with :D ) Minimal code required to PASS the tests. No speculative code.
  • 15. TDD vs Writing testsTest Driven Development A software development process Upfront design thinking Tests come first More about software design than testing Writing unit tests A way to ensure code works An after thought to confirm assertions Tests come second More about testing than software design Knowing how to write better unit tests is crucial to TDD Vs
  • 16. Feedback loop is minutes. Source http://www.agilemodeling.com/essays/costOfChange.htm
  • 17. TDD Benefits Better designed code • The interactions are already understood Clear business requirements • Tests act as a well-defined specification Improved code quality • Minimum code required to make the test pass Focus • Narrow focus. High productivity. Confidence to refactor • Touching the code after few weeks, new team members etc. Evolutionary technique • Small steps towards end goal. Few lines of code at a time. Detect errors early in the process • Assertions are already there
  • 19. Demo • NodeJS – development platform • https://nodejs.org/en/download/ • Jest – Test tool • https://jestjs.io/ A function to check strong passwords ... %mkdir password && cd $_ %git init %npm init --yes %npm i jest %mkdir test %touch test/password.test.js f()input output assertions test("description", function); e.g., test("test description", () => { expect(1+2).toBe(3); });
  • 20. 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
  • 21. 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
  • 22. TDD – Criticisms and Practicality • TDD Zealots – do this or you are wrong • Reactance theory – freedom – teams - benefits • Sometimes the first test doesn’t come naturally • Playing with code and other components first • Tests are good as long as all relevant assertions are covered. • ATDD - Acceptance test–driven development • Bad unit tests -> bad TDD • Fast test execution • TDD - needs practice • Measure test coverage
  • 23. Tools that can help us Test tools Development language JSUnit, Jasmine, Tape, Jest, Mocha, Chai, Sinon Node / Javascript 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
  • 25. Dependencies • HTTP calls, Database, File IO • Inconsistent outcome of the test • Network connectivity issues • External state changes • Time consuming, Error-prone • CI/CD pipelines • Stunt Test Doubles • Cheaper than the real one ;-) • E.g., Sinon :- Spy/Stub/Mock
  • 26. Spy Stub Mock Gather information about a function call (spying). A spy does not replace the existing function. e.g., to check if a function is called Replaces the existing function. e.g., to remove external dependencies. Replaces the whole object. e.g., Handy to test more than one function. var callback = sinon.spy(); myFunction(true, callback); sinon.assert(callback.calledOnce); var post = sinon.stub($, 'post’); post.yields(); myFunction(user, function(){} ); post.restore(); sinon.assert.calledWith(post, expectedUrl, expectedParams); var storeMock = sinon.mock(store); storeMock.expects('get').withArgs('data').retu rns(0); storeMock.expects('set').once().withArgs('data ', 1); myFunction(); storeMock.restore(); storeMock.verify();
  • 28. 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
  • 29. runtime TDD with Microservices • Different runtimes and tech stacks • Service – service interactions • Mocks • Version control Runtime Customer Object Invoice Object runtime Customer Service Invoice Service
  • 30. TDD with Microservices • Integration tests can be used to test the validity of service-service interactions • But TDD needs unit tests (short feedback loop)
  • 31. Pacts • 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
  • 34. 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 -> a JavaScript Testing utility for React
  • 36. 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() {}); • Human readable - Technical and non-technical users • TDD and BDD complements each other • Many tools, e.g., Cucumber, JBehave, RSpec.
  • 37. 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.
  • 38. Further reading • Test-Driven Development by Example – Kent Beck • http://agiledata.org/essays/tdd.html • https://www.agilealliance.org
  • 40. Versant is hiring  https://versent.workable.com/j/48ED01EAC5

Notas do Editor

  1. const checkPassword = require('../src/password’) const checkPassword = require('../src/password’) test('empty password is a bad password', () => { expect(checkPassword("")).toBe(false); }); ---- function check(pass) { if (pass.match(/[A-Z]/g || []).length < 2) { return false; } return true; } module.exports = check;