SlideShare a Scribd company logo
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 Basics
RAMU KOLLI
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
Indu Sharma Bhardwaj
 
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 3
Sagar Verma
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
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
Sagar Verma
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
Nattapong Tonprasert
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Core java
Core javaCore java
Core java
Shivaraj R
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul 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 - exercises
agorolabs
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
agorolabs
 
Computer Programming Overview
Computer Programming OverviewComputer Programming Overview
Computer Programming Overview
agorolabs
 
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
agorolabs
 
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-development
David 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 Git
msadouni
 
Présentation de git
Présentation de gitPrésentation de git
Présentation de git
Julien Blin
 
Présentation Git & GitHub
Présentation Git & GitHubPrésentation Git & GitHub
Présentation Git & GitHub
Thibault Vlacich
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger
 
Introduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaIntroduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for Java
Joris De Winne
 
Tutoriel GIT
Tutoriel GITTutoriel GIT
Tutoriel GIT
Francois ANDRE
 
Tests Logiciel
Tests LogicielTests Logiciel
Tests Logiciel
Nathaniel Richand
 
Enum Report
Enum ReportEnum Report
Enum Report
enumplatform
 
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

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
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
Jay 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/CD
Shanmuga S Muthu
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
Dave 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 Consulting
Dave White
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with Fitnesse
ClareMcLennan
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik 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 Project
GlobalLogic Ukraine
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
TEST Huddle
 
Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
Eyal 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 Salesforce
Jitendra Zaa
 
Agile testing
Agile testingAgile testing
Agile testing
Raj Indugula
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
jaredrrichardson
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
Ganesh 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_presentation
sayhi2sudarshan
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 

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

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 

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