SlideShare a Scribd company logo
1 of 31
Download to read offline
An introduction to testing and TDD
Patrick Kostjens
February 7, 2017
Java Beginners Meetup
Table of contents
1. Introduction
2. Test Driven Development
3. Unit testing in Java
4. Exercise 1
5. Exercise 2
1
Introduction
About me
Patrick Kostjens
Software Developer
2
Why testing?
To build better software faster
3
Better software
• Fewer bugs
• Easier to maintain
• Easier to change
• Safer to change
4
How to test?
Write code that checks if other code does what it is
supposed to.
5
Types of testing
1. Unit testing
2. Integration testing
3. System testing
4. Acceptance testing
6
Testing concepts
• Mocking
• e2e
• TDD
• BDD
7
Test Driven Development
Brief introduction
Writing tests to check if your code works seems good, right?
8
Brief introduction
Writing tests to check if your code works seems good, right?
But, maybe we are only testing what we expect to happen.
8
Brief introduction
Writing tests to check if your code works seems good, right?
But, maybe we are only testing what we expect to happen.
What if we write our tests before we write (bits of) code?
8
Brief introduction
Writing tests to check if your code works seems good, right?
But, maybe we are only testing what we expect to happen.
What if we write our tests before we write (bits of) code?
Test Driven Development
8
TDD workflow
9
Why TDD?
• No influence from knowledge gained while implementing
10
Why TDD?
• No influence from knowledge gained while implementing
• Immediately know if every bit of code works
10
Why TDD?
• No influence from knowledge gained while implementing
• Immediately know if every bit of code works
• Keep code as simple as possible
10
Why TDD?
• No influence from knowledge gained while implementing
• Immediately know if every bit of code works
• Keep code as simple as possible
• Make code easy to test
10
Why TDD?
• No influence from knowledge gained while implementing
• Immediately know if every bit of code works
• Keep code as simple as possible
• Make code easy to test
• Catch bugs early
10
Unit testing in Java
Tools and frameworks
Frameworks:
• JUnit
• TestNG
Tools:
• Mockito
• EasyMock
• Powermock
• Hamcrest
11
Simple test in JUnit
import org.junit.Test;
import org.junit.Assert;
public class SimpleTest {
@Test
public void test1Returns1 () {
Assert.assertEquals("1",
getAnswer (1));
}
}
12
Test preparation
public class PrepareTest {
private FizzBuzz testObject;
@Before
public void setup() {
testObject = new FizzBuzz ();
}
@Test
//...
}
13
Exercise 1
Fizz Buzz project
Take repository at:
https://github.com/patrickkostjens/fizz-buzz-exercise
Install and run using README
14
Fizz Buzz rules
• Dividable by 3? Fizz
• Dividable by 5? Buzz
• Dividable by 3 and 5? Fizz Buzz
• None of the above? Just a number
Exercise
Given a number, return the Fizz Buzz answer for that
number.
15
Easy, right?
Fizz Buzz seems to be very easy
yet
there are many solutions
See: https://ditam.github.io/posts/fizzbuzz/
16
Exercise 2
Bowling scoring system
• No project setup available
• Don’t build an interface
• Start simple!
• Try to do TDD
17
Thank you!
17

More Related Content

What's hot

8th Alg - April4
8th Alg - April48th Alg - April4
8th Alg - April4
jdurst65
 

What's hot (20)

TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
TGT#16 - Sztuka projektowania testów - Agnieszka GarwolińskaTGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
 
8th Alg - April4
8th Alg - April48th Alg - April4
8th Alg - April4
 
Testing JSF with Arquillian and Selenium
Testing JSF with Arquillian and SeleniumTesting JSF with Arquillian and Selenium
Testing JSF with Arquillian and Selenium
 
Проблемы с производительностью приложений на AngularJS и способы их решения
Проблемы с производительностью приложений на AngularJS и способы их решенияПроблемы с производительностью приложений на AngularJS и способы их решения
Проблемы с производительностью приложений на AngularJS и способы их решения
 
Barcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot FrameworkBarcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot Framework
 
Vagrant and Docker
Vagrant and DockerVagrant and Docker
Vagrant and Docker
 
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
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java Project
 
Joomla! JavaScript Testing
Joomla! JavaScript TestingJoomla! JavaScript Testing
Joomla! JavaScript Testing
 
TDD er død. Lenge leve TDD!
TDD er død. Lenge leve TDD!TDD er død. Lenge leve TDD!
TDD er død. Lenge leve TDD!
 
Wp7 tdd, bdd, mocking
Wp7 tdd, bdd, mockingWp7 tdd, bdd, mocking
Wp7 tdd, bdd, mocking
 
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
Continuous Integration, TDD & Living Documentation - Odoo Experience 2015
 
TDD with Python and App Engine
TDD with Python and App EngineTDD with Python and App Engine
TDD with Python and App Engine
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
 
Unit Testing & Test Driven Development
Unit Testing & Test Driven DevelopmentUnit Testing & Test Driven Development
Unit Testing & Test Driven Development
 
[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing Framework[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing Framework
 
Develop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConfDevelop Maintainable Apps - edUiConf
Develop Maintainable Apps - edUiConf
 
JDD2014: Continuous delivery: capitalizing high quality automated tests - Szc...
JDD2014: Continuous delivery: capitalizing high quality automated tests - Szc...JDD2014: Continuous delivery: capitalizing high quality automated tests - Szc...
JDD2014: Continuous delivery: capitalizing high quality automated tests - Szc...
 
Android TDD
Android TDDAndroid TDD
Android TDD
 

Viewers also liked

Viewers also liked (20)

Agile Testing Alliance Chapter and Meetup Details - June 2016
Agile Testing Alliance Chapter and Meetup Details - June 2016Agile Testing Alliance Chapter and Meetup Details - June 2016
Agile Testing Alliance Chapter and Meetup Details - June 2016
 
Ruby meetup 7_years_in_testing
Ruby meetup 7_years_in_testingRuby meetup 7_years_in_testing
Ruby meetup 7_years_in_testing
 
Introduction to Reactive
Introduction to ReactiveIntroduction to Reactive
Introduction to Reactive
 
Peer Meetup introduction & networking by Safaraz Ali delivered on 18th Nov 2016
Peer Meetup introduction & networking by Safaraz Ali delivered on 18th Nov 2016Peer Meetup introduction & networking by Safaraz Ali delivered on 18th Nov 2016
Peer Meetup introduction & networking by Safaraz Ali delivered on 18th Nov 2016
 
Integration Testing for Polyglot Ecosystems
Integration Testing for Polyglot EcosystemsIntegration Testing for Polyglot Ecosystems
Integration Testing for Polyglot Ecosystems
 
Paris Qa meetup - The testing family
Paris Qa meetup - The testing familyParis Qa meetup - The testing family
Paris Qa meetup - The testing family
 
Puppet meetup testing
Puppet meetup testingPuppet meetup testing
Puppet meetup testing
 
Agille Testing Meetup 1
Agille Testing Meetup 1Agille Testing Meetup 1
Agille Testing Meetup 1
 
Ata pune 12 meetup 17 September 2016 - Introduction by Amol Deshpande
Ata pune 12 meetup 17 September 2016 - Introduction by Amol DeshpandeAta pune 12 meetup 17 September 2016 - Introduction by Amol Deshpande
Ata pune 12 meetup 17 September 2016 - Introduction by Amol Deshpande
 
Acunu Cassandra London Meetup
Acunu Cassandra London MeetupAcunu Cassandra London Meetup
Acunu Cassandra London Meetup
 
Ata pune 12 meetup Future of testing 17 sep 2016 by sanjay upadhyay
Ata pune 12 meetup  Future of testing 17 sep 2016 by sanjay upadhyayAta pune 12 meetup  Future of testing 17 sep 2016 by sanjay upadhyay
Ata pune 12 meetup Future of testing 17 sep 2016 by sanjay upadhyay
 
Paris Qa Meetup - Testing Family
Paris Qa Meetup -  Testing FamilyParis Qa Meetup -  Testing Family
Paris Qa Meetup - Testing Family
 
Meetup kickoff slides - Perfecto Mobile, September 2014
Meetup kickoff slides - Perfecto Mobile, September 2014Meetup kickoff slides - Perfecto Mobile, September 2014
Meetup kickoff slides - Perfecto Mobile, September 2014
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as Code
 
RST - Makati Testers Meetup
RST - Makati Testers MeetupRST - Makati Testers Meetup
RST - Makati Testers Meetup
 
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
Meetup Testing Workshop 2016 - Gatling para pruebas de performance - Federico...
 
Helsinki Legal Tech Meetup introduction
Helsinki Legal Tech Meetup introductionHelsinki Legal Tech Meetup introduction
Helsinki Legal Tech Meetup introduction
 
NoVA UX Meetup: Product Testing and Data-informed Design
NoVA UX Meetup: Product Testing and Data-informed DesignNoVA UX Meetup: Product Testing and Data-informed Design
NoVA UX Meetup: Product Testing and Data-informed Design
 
Tundra at Agile Mississauga Meetup Kick off Event
Tundra at Agile Mississauga Meetup Kick off EventTundra at Agile Mississauga Meetup Kick off Event
Tundra at Agile Mississauga Meetup Kick off Event
 
The Invisible Art Of Software Testing
The Invisible Art Of Software TestingThe Invisible Art Of Software Testing
The Invisible Art Of Software Testing
 

Similar to Java Beginners Meetup February 2017: Testing and TDD

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
bhochhi
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
Seapine Software
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Joseph Yoder
 
Pragmatic notdogmatictdd agile2012
Pragmatic notdogmatictdd   agile2012Pragmatic notdogmatictdd   agile2012
Pragmatic notdogmatictdd agile2012
drewz lin
 

Similar to Java Beginners Meetup February 2017: Testing and TDD (20)

Android tdd
Android tddAndroid tdd
Android tdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
Testacular
TestacularTestacular
Testacular
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Essential tdd lesson-brief-intro-tdd
Essential tdd lesson-brief-intro-tddEssential tdd lesson-brief-intro-tdd
Essential tdd lesson-brief-intro-tdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
 
Pragmatic notdogmatictdd agile2012
Pragmatic notdogmatictdd   agile2012Pragmatic notdogmatictdd   agile2012
Pragmatic notdogmatictdd agile2012
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

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...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Java Beginners Meetup February 2017: Testing and TDD