SlideShare a Scribd company logo
1 of 33
Java 201 – Intro to Test-Driven
Development in Java
Agenda
• TDD Overview
• Test Frameworks
• Setting Up your IDE
• Writing your first Unit Test
• Anatomy of a Unit Test
• Hands-on Exercise
Intro to Test-Driven Development
in Java
TDD Overview
TDD Overview
• What is TDD
• Why TDD
• Feedback Loop
• TDD Workflow
What is TDD?
• Technique for specifying system features with
tests
• Tests are written before production code
• Simple, repeated, short-cycled mechanism
• Automated mechanism for regression testing
of code changes
Why TDD?
• Improves code quality
• Minimises defects
• Increases code maintainability
• Reduces the cost of change
• Provides a quick feedback
• Acts as documentation for your code
• Reduces fear of breaking things
• It is fun and infectious 
Feedback Loop
PDCA Explained
• PLAN
– Establish the objectives
– Identify steps required to meet the objective
• DO
– Execute the steps to meet the objective
• CHECK
– Study actual results and compare against expected results
– Look for completeness in meeting the objectives
• ACT
– If CHECK step shows objectives met vs. with the plan,
repeat with next objective else rework and CHECK again
TDD Workflow
Intro to Test-Driven Development
in Java
Test Frameworks
What is a Test Framework?
• An abstract set of…
– concepts, processes, procedures, environments
• Where automated tests are…
– designed, implemented and executed
• Includes physical structures for…
– test creation
– test execution
• As well as…
– logical interactions amongst components
Why Test Frameworks?
• Provides the basis of test automation
• Simplifies test automation efforts
• Provides concepts and tools that support
automated testing
Common Test Frameworks
• Code Testing
– Junit (http://www.junit.org)
– TestNG (http://testng.org)
• UI Testing
– Selenium (www.selenium.org)
– Appium (http://appium.io/)
• API Testing
– SoapUI (http://www.soapui.org)
– RestAssured (https://code.google.com/p/rest-assured)
Intro to Test-Driven Development
in Java
Setting Up your IDE
Setting Up
• Required Software
• Download JUnit
• Create Java201 Project
• Add JUnit to the Classpath
• Create HelloGreetingTest
• Run the HelloGreetingTest
• Create the HelloGreeting class
• Re-run the HelloGreetingTest
Required Software
• IDE
• Java SDK
– http://www.oracle.com/technetwork/java/javase/
downloads/jdk8-downloads-2133151.html
• JUnit
– www.junit.org
Download JUnit
• Download the following files from
www.junit.org to a folder on your hard drive
– junit.jar
– hamcrest-core.jar
Create Java201 Project
• Create new project named Java201
• Create a new source folder named test in the
java201 project
• Create a lib folder in the Java201 project
• In the test source folder, create the
java201.greetings package
Add JUnit to the Classpath
• Copy the junit.jar and hamcrest-core.jar files to
the lib folder of your project
• Refresh the project to import the new contents
of the lib folder
• In Eclipse, click on the Java201 project, select
File>Properties>Build Path and click on
Libraries tab
• Click Add JARs, browse to the project lib folder,
select both jar files and click OK twice
Create HelloGreetingTest.java
• In Eclipse, Right-click the test folder, select New>JUnit Test Case,
enter HelloGreetingTest in the Name field and click Finish
HelloGreetingTest.java
Implement HelloGreetingTest.java
Run the HelloGreetingTest
• In Eclipse, Right-click the HelloGreetingTest and select
Run As>JUnit Test
Create HelloGreeting class
• In Eclipse, right-click the src folder and select New>Class, enter
HelloGreeting as class name and click Finish
• Create a sayHello() method that returns the String “Hello, TDD!”
Re-run the HelloGreetingTest
• Declare and initialise HelloGreeting object and
assert it returns “Hello, TDD!” and rerun the test
Intro to Test-Driven Development
in Java
Anatomy of a Unit Test
Anatomy of a Unit Test
Declaration of
class under test
setUp() runs once
before each test method
A test method
Initialization of
class under test
tearDown() runs once
after each test method
Checking test results
Intro to Test-Driven Development
in Java
Hands-on Exercise
Exercise: Game of Cards
• Using TDD, create the following building blocks of a
typical card game
– Card
• Has a suite (Club, Heart, Diamond, Spade) and rank (2-10, Jack,
Queen, King, Ace)
• Ace is highest card
– Hand
• Consists of one or more Cards
– Deck
• Contains 52 Cards, 13 cards per suite
– Dealer
• Deals cards from a deck
• Each player will be dealt a Hand of Cards
Card
rank
suite
getRank() : Rank
setRank() : void
getSuite() : Suite
setSuite() : void
Hand
cards
maxCards
getNoOfCards() : int
drawCard(): Card
addCard() : void
Deck
cards
getCards(int noOFCards) :
List<Card>
Dealer
deck
deal(noOfCards) : Hand
Game of Cards Domain Model
Solution: Game of Cards
https://github.com/hawkmanacademy/java201
Resources
• UML Distilled - http://amzn.to/1BBHcXi
• Test Driven Development –
http://amzn.to/1xqPllN
• XUnit Patterns - http://xunitpatterns.com/
• Junit – www.junit.org

More Related Content

What's hot

Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 

What's hot (12)

Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Core java
Core javaCore java
Core java
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 

Viewers also liked

Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercisesagorolabs
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agileagorolabs
 
Computer Programming Overview
Computer Programming OverviewComputer Programming Overview
Computer Programming Overviewagorolabs
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structuresagorolabs
 
C'est si simple git ! (devoxx france 2012)
C'est si simple git ! (devoxx france 2012)C'est si simple git ! (devoxx france 2012)
C'est si simple git ! (devoxx france 2012)Ulrich VACHON
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-developmentDavid Paluy
 
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?Nicolas Ruffel
 
TDD - Short for Test Driven Development!
TDD - Short for Test Driven Development!TDD - Short for Test Driven Development!
TDD - Short for Test Driven Development!Bradley Cypert
 
Présentation du versioning avec Git
Présentation du versioning avec GitPrésentation du versioning avec Git
Présentation du versioning avec Gitmsadouni
 
Présentation de git
Présentation de gitPrésentation de git
Présentation de gitJulien Blin
 
Présentation Git & GitHub
Présentation Git & GitHubPrésentation Git & GitHub
Présentation Git & GitHubThibault Vlacich
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
Introduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaIntroduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaJoris De Winne
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5Bianca Teşilă
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)Waheed Khalid
 

Viewers also liked (20)

Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercises
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
 
Computer Programming Overview
Computer Programming OverviewComputer Programming Overview
Computer Programming Overview
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
C'est si simple git ! (devoxx france 2012)
C'est si simple git ! (devoxx france 2012)C'est si simple git ! (devoxx france 2012)
C'est si simple git ! (devoxx france 2012)
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-development
 
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?
Mix it 2016 - Software craftsmanship : le chainon manquant de l’agilité ?
 
TDD - Short for Test Driven Development!
TDD - Short for Test Driven Development!TDD - Short for Test Driven Development!
TDD - Short for Test Driven Development!
 
Présentation du versioning avec Git
Présentation du versioning avec GitPrésentation du versioning avec Git
Présentation du versioning avec Git
 
Présentation de git
Présentation de gitPrésentation de git
Présentation de git
 
Présentation Git & GitHub
Présentation Git & GitHubPrésentation Git & GitHub
Présentation Git & GitHub
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Introduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaIntroduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for Java
 
Tutoriel GIT
Tutoriel GITTutoriel GIT
Tutoriel GIT
 
Tests Logiciel
Tests LogicielTests Logiciel
Tests Logiciel
 
Java Day-2
Java Day-2Java Day-2
Java Day-2
 
Java Day-7
Java Day-7Java Day-7
Java Day-7
 
Enum Report
Enum ReportEnum Report
Enum Report
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
 

Similar to Java 201 Intro to Test Driven Development in Java

Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!Ivan Ivanov
 
Test Driven Development & CI/CD
Test Driven Development & CI/CDTest Driven Development & CI/CD
Test Driven Development & CI/CDShanmuga S Muthu
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth ConsultingUnit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth ConsultingDave White
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseClareMcLennan
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
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 ProjectGlobalLogic Ukraine
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy CodeEyal Golan
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceJitendra Zaa
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
 
Selenium web driver_2.0_presentation
Selenium web driver_2.0_presentationSelenium web driver_2.0_presentation
Selenium web driver_2.0_presentationsayhi2sudarshan
 

Similar to Java 201 Intro to Test Driven Development in Java (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!
 
Test Driven Development & CI/CD
Test Driven Development & CI/CDTest Driven Development & CI/CD
Test Driven Development & CI/CD
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth ConsultingUnit Testing -  Calgary .NET User Group - Nov 26 2014 - Depth Consulting
Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with Fitnesse
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
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
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 
Agile testing
Agile testingAgile testing
Agile testing
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Eclipse UI automation
Eclipse UI automationEclipse UI automation
Eclipse UI automation
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Selenium web driver_2.0_presentation
Selenium web driver_2.0_presentationSelenium web driver_2.0_presentation
Selenium web driver_2.0_presentation
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 

Recently uploaded

StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabbereGrabber
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...OnePlan Solutions
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024vaibhav130304
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfmbmh111980
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Soroosh Khodami
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationHelp Desk Migration
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfDeskTrack
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...rajkumar669520
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Primacy Infotech
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)Max Lee
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdfkalichargn70th171
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 

Recently uploaded (20)

Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 

Java 201 Intro to Test Driven Development in Java

  • 1. Java 201 – Intro to Test-Driven Development in Java
  • 2. Agenda • TDD Overview • Test Frameworks • Setting Up your IDE • Writing your first Unit Test • Anatomy of a Unit Test • Hands-on Exercise
  • 3. Intro to Test-Driven Development in Java TDD Overview
  • 4. TDD Overview • What is TDD • Why TDD • Feedback Loop • TDD Workflow
  • 5. What is TDD? • Technique for specifying system features with tests • Tests are written before production code • Simple, repeated, short-cycled mechanism • Automated mechanism for regression testing of code changes
  • 6. Why TDD? • Improves code quality • Minimises defects • Increases code maintainability • Reduces the cost of change • Provides a quick feedback • Acts as documentation for your code • Reduces fear of breaking things • It is fun and infectious 
  • 8. PDCA Explained • PLAN – Establish the objectives – Identify steps required to meet the objective • DO – Execute the steps to meet the objective • CHECK – Study actual results and compare against expected results – Look for completeness in meeting the objectives • ACT – If CHECK step shows objectives met vs. with the plan, repeat with next objective else rework and CHECK again
  • 10. Intro to Test-Driven Development in Java Test Frameworks
  • 11. What is a Test Framework? • An abstract set of… – concepts, processes, procedures, environments • Where automated tests are… – designed, implemented and executed • Includes physical structures for… – test creation – test execution • As well as… – logical interactions amongst components
  • 12. Why Test Frameworks? • Provides the basis of test automation • Simplifies test automation efforts • Provides concepts and tools that support automated testing
  • 13. Common Test Frameworks • Code Testing – Junit (http://www.junit.org) – TestNG (http://testng.org) • UI Testing – Selenium (www.selenium.org) – Appium (http://appium.io/) • API Testing – SoapUI (http://www.soapui.org) – RestAssured (https://code.google.com/p/rest-assured)
  • 14. Intro to Test-Driven Development in Java Setting Up your IDE
  • 15. Setting Up • Required Software • Download JUnit • Create Java201 Project • Add JUnit to the Classpath • Create HelloGreetingTest • Run the HelloGreetingTest • Create the HelloGreeting class • Re-run the HelloGreetingTest
  • 16. Required Software • IDE • Java SDK – http://www.oracle.com/technetwork/java/javase/ downloads/jdk8-downloads-2133151.html • JUnit – www.junit.org
  • 17. Download JUnit • Download the following files from www.junit.org to a folder on your hard drive – junit.jar – hamcrest-core.jar
  • 18. Create Java201 Project • Create new project named Java201 • Create a new source folder named test in the java201 project • Create a lib folder in the Java201 project • In the test source folder, create the java201.greetings package
  • 19. Add JUnit to the Classpath • Copy the junit.jar and hamcrest-core.jar files to the lib folder of your project • Refresh the project to import the new contents of the lib folder • In Eclipse, click on the Java201 project, select File>Properties>Build Path and click on Libraries tab • Click Add JARs, browse to the project lib folder, select both jar files and click OK twice
  • 20. Create HelloGreetingTest.java • In Eclipse, Right-click the test folder, select New>JUnit Test Case, enter HelloGreetingTest in the Name field and click Finish
  • 23. Run the HelloGreetingTest • In Eclipse, Right-click the HelloGreetingTest and select Run As>JUnit Test
  • 24. Create HelloGreeting class • In Eclipse, right-click the src folder and select New>Class, enter HelloGreeting as class name and click Finish • Create a sayHello() method that returns the String “Hello, TDD!”
  • 25. Re-run the HelloGreetingTest • Declare and initialise HelloGreeting object and assert it returns “Hello, TDD!” and rerun the test
  • 26.
  • 27. Intro to Test-Driven Development in Java Anatomy of a Unit Test
  • 28. Anatomy of a Unit Test Declaration of class under test setUp() runs once before each test method A test method Initialization of class under test tearDown() runs once after each test method Checking test results
  • 29. Intro to Test-Driven Development in Java Hands-on Exercise
  • 30. Exercise: Game of Cards • Using TDD, create the following building blocks of a typical card game – Card • Has a suite (Club, Heart, Diamond, Spade) and rank (2-10, Jack, Queen, King, Ace) • Ace is highest card – Hand • Consists of one or more Cards – Deck • Contains 52 Cards, 13 cards per suite – Dealer • Deals cards from a deck • Each player will be dealt a Hand of Cards
  • 31. Card rank suite getRank() : Rank setRank() : void getSuite() : Suite setSuite() : void Hand cards maxCards getNoOfCards() : int drawCard(): Card addCard() : void Deck cards getCards(int noOFCards) : List<Card> Dealer deck deal(noOfCards) : Hand Game of Cards Domain Model
  • 32. Solution: Game of Cards https://github.com/hawkmanacademy/java201
  • 33. Resources • UML Distilled - http://amzn.to/1BBHcXi • Test Driven Development – http://amzn.to/1xqPllN • XUnit Patterns - http://xunitpatterns.com/ • Junit – www.junit.org

Editor's Notes

  1. Tests Keep you out of the (time hungry) debugger! Tests Reduce Bugs in New Features Tests Reduce Bugs in Existing Features Tests Reduce the Cost of Change Tests Improve Design Tests Allow Refactoring Tests Constrain Features Tests Defend Against Other Programmers Testing Is Fun Testing Forces You to Slow Down and Think Testing Makes Development Faster Tests Reduce Fear