SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
Test Driven Development (TDD) Workshop!
!
Anjana Somathilake!
Director, Engineering and Architecture at Leapset!

!
Proprietary & Confidential
Coverage!
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!
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!!

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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 EditionFernando Cejas
 
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
 
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
 

Semelhante a 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
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Test Driven Development - Workshop

  • 1. Test Driven Development (TDD) Workshop! ! Anjana Somathilake! Director, Engineering and Architecture at Leapset! ! Proprietary & Confidential
  • 3.
  • 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!
  • 16.
  • 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”!