SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Test Driven Development (TDD) Workshop!
!
Anjana Somathilake!
Director, Engineering and Architecture at Leapset!

!
Proprietary & Confidential
Coverage!
Test Driven Development - Workshop
Problem #1!

In the beginning, your source code
was perfect!!
Then it all changed…!
Problem #2!

“Fix one thing, break another!”!
Problem #3!

You know how to build it, !
but you don’t know how to prove
that it works!!
Problem #4!

What if I change this piece of code?!
Problem #5!

Change Happens !
Problem #6!

Developers get to know about the
issues only after the QA testing.!
Types of Testing

!

• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 
• 

Unit testing!
Installation testing!
Compatibility testing!
Smoke and sanity testing!
Regression testing!
Acceptance testing!
Functional testing!
Destructive testing!
Performance testing!
Usability testing!
Accessibility testing!
Security testing!
Integration testing!
A/B testing!
Scope!

•  Introduction to TDD!
•  Unit Testing!

!

•  Refactoring!
Introduction to Test Driven Development

!
TDD as a Habit!

“TDD is NOT an expert level
practice, it is rather simple habit
of writing the test first!”!
Traditional vs. TDD !
What TDD is all about?!

Testing?!

Design!
Test Driven Development - Workshop
TDD Lifecycle

!

Write a
failing test

Refactor

Write the
code to
make this
test pass
TDD Process

!
TDD Lifecycle - Detailed

!

Add a Test – Each new feature begins with writing a test. This test must
initially fail since it is written before the feature has been coded.!
!
Run All Tests – validate that the test-harnesses work and that the new
test does not mistakenly pass without requiring any new code.!
!
Write Development Code – That will cause the test to pass.!
!
Run Tests – If all test cases pass the code meets all the tested
requirements.!
!
Clean Up Code – Refactor code to make production ready removing
any dummy/stub code.!
!
Repeat Process – Starting with another new test, the cycle is then
repeated to push forward the functionality.!
TDD Results!

• 

Testable Code

• 

Working Software

• 

Enforce Thinking Ahead 

• 

Clean & Maintainable Code

• 

Increment Code Quality

• 

Faster Feedback

• 

Bring Back the Joy of Coding
TDD in a nutshell!

1.  Write a test!
2.  Watch the test fail!
3.  Write just enough code !
4.  Pass the test!
5.  Refactor, remove duplications!
6.  Pass the test again!
TDD in extremely simplified

!

•  Write a failing test!
•  Pass the test!
•  Repeat!
Unit Testing

!
Unit Testing – Software Equivalent of Exercising !
Unit Testing

!

A unit test is a piece of code that
invokes a unit of work in the system
and then checks a single
assumption about the behavior of
that unit of work.!
Unit of Work

!

•  A unit of work is a single logical functional
use case in the system that can be invoked
by some public interface (in most cases)!
•  A unit of work can span a single method, a
whole class or multiple classes working
together to achieve one single logical
purpose that can be verified!
Unit Test Frameworks!

SUnit!
Smalltalk!
!
JUnit!
Java!
!
NUnit!
.NET!
!
OCUnit!
Objective-c!
!
(etc.)!
JUnit Framework!
Assertions!

A confident and forceful statement
of fact or belief.!
!
“I assert that the earth is round”!
!
But if the assertion is wrong, then there is something fundamentally
flawed about the understanding.!
!

This is the fundamental principle used in unit
testing.!
Assertions in coding!

•  At this point in my code, I assert these two
strings are equal!
!
•  At this point in my code, I assert this object
is not null!
Assert in JUnit!
assertEquals("failure - strings not same", 5l, 5l);
assertNotNull("should not be null", new Object());

int objA[] = new int[10];
int objB[] = new int[10];
assertArrayEquals(objA, objB);

https://github.com/junit-team/junit/wiki/Assertions
Bank Account!

Bank Account
balance
getBalance()
deposit()
withdraw()
Bank Account!

Sprint 1!
!
• 
• 
• 
• 

Create a bank account!
Deposit 100!
Withdraw 50!
Check the balance!

!
!
Sprint 2
!
•  Max withdrawal is 5000!
•  Add penalty of 5, if withdraw more than the balance!
!
!
Sprint 3
•  Throw an exception if negative value is passed to the deposit method
Unit Test Structure!

Arrange

Act

Assert

@Test
public void deposit500(){
BankAccount bankAcct = new BankAccount();
bankAcct.deposit(500);
assertEquals(500, bankAcct.getBalance());
}
Unit Test Code Coverage!

How much unit testing is enough?!
!
How to measure the coverage?!
!
Is there a tool for this?!
Unit Test Code Coverage!
Benefits of Unit Tests



!

•  Fast!
•  Easy to write and maintain!
•  Better code coverage!
•  When fail, provide insight into the
problem!
Refactoring!
Refactoring!

Refactoring is the process of clarifying and
simplifying the design of existing code,
without changing its behavior.!
!
!
At the smallest scale, a “refactoring” is a
minimal, safe transformation of your code that
keeps its behavior unchanged.!
Most well-known Refactoring Patterns.!
Inline Temporary Variable

!
Replace all uses of a local variable by inserting copies of its assigned value.!

public double applyDiscount() {
double basePrice = _cart.totalPrice();
return basePrice * discount();
}

public double applyDiscount() {
return _cart.totalPrice() * discount();
}
Extract method!
Create a new method by extracting a code fragment from an existing!
method.!
public void report(Writer out, List<Machine> machines) throws IOException {
for (Machine machine : machines) {
out.write(“Machine “ + machine.name());
if (machine.bin() != null)
out.write(“ bin=” + machine.bin());
out.write(“n”);
}
}

public void report(Writer out, List<Machine> machines) throws IOException {
for (Machine machine : machines) {
reportMachine(out, machine);
}
}
private void reportMachine(Writer out, Machine machine) throws IOException {
out.write(“Machine “ + machine.name());
if (machine.bin() != null){
out.write(“ bin=” + machine.bin());
}
out.write(“n”);
}
String Calculator Exercise!

1.  Create a simple String calculator with a method int Add(string
numbers)!
1.  The method can take 0, 1 or 2 numbers, and will return their sum
(for an empty string it will return 0) for example “” or “1” or “1,2”!
2.  Start with the simplest test case of an empty string and move to 1
and two numbers!
3.  Remember to solve things as simply as possible so that you force
yourself to write tests you did not think about!
4.  Remember to refactor after each passing test!
2.  Allow the Add method to handle an unknown amount of numbers!
!
3.  Calling Add with a negative number will throw an exception “negatives
not allowed”!
Thank You!!

Weitere ähnliche Inhalte

Was ist angesagt?

Calabash my understanding
Calabash my understandingCalabash my understanding
Calabash my understandingFARHAN SUMBUL
 
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in Mind
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in MindSauceCon 2017: Building a Continuous Delivery Pipeline with Testing in Mind
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in MindSauce Labs
 
Using Selenium To Test Mobile? Meet Appium!
Using Selenium To Test Mobile? Meet Appium!Using Selenium To Test Mobile? Meet Appium!
Using Selenium To Test Mobile? Meet Appium!Sauce Labs
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choicetoddbr
 
Advanced Mocking for Swagger APIs
Advanced Mocking for Swagger APIsAdvanced Mocking for Swagger APIs
Advanced Mocking for Swagger APIsSmartBear
 
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -sandeep kumar gupta
 
API Test Automation Tips and Tricks
API Test Automation Tips and TricksAPI Test Automation Tips and Tricks
API Test Automation Tips and Trickstesthive
 
Automate REST API Testing
Automate REST API TestingAutomate REST API Testing
Automate REST API TestingTechWell
 
Shift left-csun-sagar-barbhaya
Shift left-csun-sagar-barbhayaShift left-csun-sagar-barbhaya
Shift left-csun-sagar-barbhayaSAGAR BARBHAYA
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API TestingSauce Labs
 
Ios driver presentation copy
Ios driver presentation copyIos driver presentation copy
Ios driver presentation copyDavid O'Dowd
 
10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing
10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing
10x Test Coverage, Less Drama: Shift Left Functional & Performance TestingSauce Labs
 
SauceCon 2017: test.allTheThings(): Digital Edition
SauceCon 2017: test.allTheThings(): Digital EditionSauceCon 2017: test.allTheThings(): Digital Edition
SauceCon 2017: test.allTheThings(): Digital EditionSauce Labs
 
Do's and Don'ts of APIs
Do's and Don'ts of APIsDo's and Don'ts of APIs
Do's and Don'ts of APIsJason Harmon
 
Wheat - Mobile functional test automation
Wheat - Mobile functional test automationWheat - Mobile functional test automation
Wheat - Mobile functional test automationSunny Tambi
 
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.Diogo Lucas
 
Selenium Camp 2016
Selenium Camp 2016Selenium Camp 2016
Selenium Camp 2016Dan Cuellar
 

Was ist angesagt? (20)

Calabash my understanding
Calabash my understandingCalabash my understanding
Calabash my understanding
 
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in Mind
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in MindSauceCon 2017: Building a Continuous Delivery Pipeline with Testing in Mind
SauceCon 2017: Building a Continuous Delivery Pipeline with Testing in Mind
 
Using Selenium To Test Mobile? Meet Appium!
Using Selenium To Test Mobile? Meet Appium!Using Selenium To Test Mobile? Meet Appium!
Using Selenium To Test Mobile? Meet Appium!
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
 
Advanced Mocking for Swagger APIs
Advanced Mocking for Swagger APIsAdvanced Mocking for Swagger APIs
Advanced Mocking for Swagger APIs
 
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -
Mca 02 year_exp_unit_automation_testing_ldra_rtrt_c -
 
How to define an api
How to define an apiHow to define an api
How to define an api
 
React a11y-csun
React a11y-csunReact a11y-csun
React a11y-csun
 
API Test Automation Tips and Tricks
API Test Automation Tips and TricksAPI Test Automation Tips and Tricks
API Test Automation Tips and Tricks
 
Automate REST API Testing
Automate REST API TestingAutomate REST API Testing
Automate REST API Testing
 
Shift left-csun-sagar-barbhaya
Shift left-csun-sagar-barbhayaShift left-csun-sagar-barbhaya
Shift left-csun-sagar-barbhaya
 
Calabash for iPhone apps
Calabash for iPhone appsCalabash for iPhone apps
Calabash for iPhone apps
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API Testing
 
Ios driver presentation copy
Ios driver presentation copyIos driver presentation copy
Ios driver presentation copy
 
10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing
10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing
10x Test Coverage, Less Drama: Shift Left Functional & Performance Testing
 
SauceCon 2017: test.allTheThings(): Digital Edition
SauceCon 2017: test.allTheThings(): Digital EditionSauceCon 2017: test.allTheThings(): Digital Edition
SauceCon 2017: test.allTheThings(): Digital Edition
 
Do's and Don'ts of APIs
Do's and Don'ts of APIsDo's and Don'ts of APIs
Do's and Don'ts of APIs
 
Wheat - Mobile functional test automation
Wheat - Mobile functional test automationWheat - Mobile functional test automation
Wheat - Mobile functional test automation
 
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
YAGNI, YMMV and APIs: building a hybrid strategy for your API platform.
 
Selenium Camp 2016
Selenium Camp 2016Selenium Camp 2016
Selenium Camp 2016
 

Andere mochten auch

BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberKMS Technology
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with CucumberBrandon Keepers
 

Andere mochten auch (7)

BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 
BDD in Action - building software that matters
BDD in Action - building software that mattersBDD in Action - building software that matters
BDD in Action - building software that matters
 

Ähnlich wie Test Driven Development - Workshop

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping QualityMichael Roufa
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroPaul Boos
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practiceintive
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Maxim Zaks
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareChris Weldon
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Editionpenanochizzo
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionFernando Cejas
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applicationsBabak Naffas
 
Good Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality CodeGood Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality CodeFlorin Coros
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engineIlya Puchka
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit TestingSadaaki Emura
 

Ähnlich wie Test Driven Development - Workshop (20)

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping Quality
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver Software
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
eXtreme Programming
eXtreme ProgrammingeXtreme Programming
eXtreme Programming
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Edition
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Edition
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Good Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality CodeGood Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality Code
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit Testing
 
AspectMock
AspectMockAspectMock
AspectMock
 

Kürzlich hochgeladen

Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 

Kürzlich hochgeladen (20)

Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 

Test Driven Development - Workshop

  • 1. Test Driven Development (TDD) Workshop! ! Anjana Somathilake! Director, Engineering and Architecture at Leapset! ! Proprietary & Confidential
  • 4. Problem #1! In the beginning, your source code was perfect!! Then it all changed…!
  • 5. Problem #2! “Fix one thing, break another!”!
  • 6. Problem #3! You know how to build it, ! but you don’t know how to prove that it works!!
  • 7. Problem #4! What if I change this piece of code?!
  • 9. Problem #6! Developers get to know about the issues only after the QA testing.!
  • 10. Types of Testing
 ! •  •  •  •  •  •  •  •  •  •  •  •  •  •  Unit testing! Installation testing! Compatibility testing! Smoke and sanity testing! Regression testing! Acceptance testing! Functional testing! Destructive testing! Performance testing! Usability testing! Accessibility testing! Security testing! Integration testing! A/B testing!
  • 11. Scope! •  Introduction to TDD! •  Unit Testing! ! •  Refactoring!
  • 12. Introduction to Test Driven Development
 !
  • 13. TDD as a Habit! “TDD is NOT an expert level practice, it is rather simple habit of writing the test first!”!
  • 15. What TDD is all about?! Testing?! Design!
  • 17. TDD Lifecycle
 ! Write a failing test Refactor Write the code to make this test pass
  • 19. TDD Lifecycle - Detailed
 ! Add a Test – Each new feature begins with writing a test. This test must initially fail since it is written before the feature has been coded.! ! Run All Tests – validate that the test-harnesses work and that the new test does not mistakenly pass without requiring any new code.! ! Write Development Code – That will cause the test to pass.! ! Run Tests – If all test cases pass the code meets all the tested requirements.! ! Clean Up Code – Refactor code to make production ready removing any dummy/stub code.! ! Repeat Process – Starting with another new test, the cycle is then repeated to push forward the functionality.!
  • 20. TDD Results! •  Testable Code •  Working Software •  Enforce Thinking Ahead •  Clean & Maintainable Code •  Increment Code Quality •  Faster Feedback •  Bring Back the Joy of Coding
  • 21. TDD in a nutshell! 1.  Write a test! 2.  Watch the test fail! 3.  Write just enough code ! 4.  Pass the test! 5.  Refactor, remove duplications! 6.  Pass the test again!
  • 22. TDD in extremely simplified
 ! •  Write a failing test! •  Pass the test! •  Repeat!
  • 24. Unit Testing – Software Equivalent of Exercising !
  • 25. Unit Testing
 ! A unit test is a piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work.!
  • 26. Unit of Work
 ! •  A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases)! •  A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified!
  • 29. Assertions! A confident and forceful statement of fact or belief.! ! “I assert that the earth is round”! ! But if the assertion is wrong, then there is something fundamentally flawed about the understanding.! ! This is the fundamental principle used in unit testing.!
  • 30. Assertions in coding! •  At this point in my code, I assert these two strings are equal! ! •  At this point in my code, I assert this object is not null!
  • 31. Assert in JUnit! assertEquals("failure - strings not same", 5l, 5l); assertNotNull("should not be null", new Object()); int objA[] = new int[10]; int objB[] = new int[10]; assertArrayEquals(objA, objB); https://github.com/junit-team/junit/wiki/Assertions
  • 33. Bank Account! Sprint 1! ! •  •  •  •  Create a bank account! Deposit 100! Withdraw 50! Check the balance! ! ! Sprint 2 ! •  Max withdrawal is 5000! •  Add penalty of 5, if withdraw more than the balance! ! ! Sprint 3 •  Throw an exception if negative value is passed to the deposit method
  • 34. Unit Test Structure! Arrange Act Assert @Test public void deposit500(){ BankAccount bankAcct = new BankAccount(); bankAcct.deposit(500); assertEquals(500, bankAcct.getBalance()); }
  • 35. Unit Test Code Coverage! How much unit testing is enough?! ! How to measure the coverage?! ! Is there a tool for this?!
  • 36. Unit Test Code Coverage!
  • 37. Benefits of Unit Tests
 
 ! •  Fast! •  Easy to write and maintain! •  Better code coverage! •  When fail, provide insight into the problem!
  • 39. Refactoring! Refactoring is the process of clarifying and simplifying the design of existing code, without changing its behavior.! ! ! At the smallest scale, a “refactoring” is a minimal, safe transformation of your code that keeps its behavior unchanged.!
  • 41. Inline Temporary Variable
 ! Replace all uses of a local variable by inserting copies of its assigned value.! public double applyDiscount() { double basePrice = _cart.totalPrice(); return basePrice * discount(); } public double applyDiscount() { return _cart.totalPrice() * discount(); }
  • 42. Extract method! Create a new method by extracting a code fragment from an existing! method.! public void report(Writer out, List<Machine> machines) throws IOException { for (Machine machine : machines) { out.write(“Machine “ + machine.name()); if (machine.bin() != null) out.write(“ bin=” + machine.bin()); out.write(“n”); } } public void report(Writer out, List<Machine> machines) throws IOException { for (Machine machine : machines) { reportMachine(out, machine); } } private void reportMachine(Writer out, Machine machine) throws IOException { out.write(“Machine “ + machine.name()); if (machine.bin() != null){ out.write(“ bin=” + machine.bin()); } out.write(“n”); }
  • 43. String Calculator Exercise! 1.  Create a simple String calculator with a method int Add(string numbers)! 1.  The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”! 2.  Start with the simplest test case of an empty string and move to 1 and two numbers! 3.  Remember to solve things as simply as possible so that you force yourself to write tests you did not think about! 4.  Remember to refactor after each passing test! 2.  Allow the Add method to handle an unknown amount of numbers! ! 3.  Calling Add with a negative number will throw an exception “negatives not allowed”!