SlideShare a Scribd company logo
1 of 28
Download to read offline
Test Driven Development
(TDD)
Sameer Soni
@_sameersoni
What TDD is not
• is not about Testing
• is not Test Last
What TDD is
is about
evolving the design of the system through Tests.
Game Of Life - Stories
1. Any live cell with fewer than two live neighbours dies, as if caused by
under-population.
2. Any live cell with two or three live neighbours lives on to the next
generation.
3. Any live cell with more than three live neighbours dies, as if by
overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live cell, as
if by reproduction.
Specify what test should do
[TestClass]	
  
	
  	
  	
  	
  public	
  class	
  GameOfLifeTest	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  [TestMethod]	
  
	
  	
  	
  	
  	
  	
  	
  	
  public	
  void	
  LiveCell_WithLessThanTwoNeighbour_Dies()	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //Given	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  CellState	
  cellState	
  =	
  CellState.ALIVE;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  int	
  neighbourCount	
  =	
  1;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //When	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  CellState	
  result	
  =	
  LifeRules.GetNewState(cellState,	
  neighbourCount);	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //Then	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Assert.AreEqual(CellState.DEAD,	
  result);	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  }	
  
}
Write enough to compile
public	
  class	
  LifeRules	
  
{	
  
	
  	
  	
  public	
  static	
  CellState	
  GetNewState(CellState	
  cellState,	
  int	
  neighbourCount)	
  
	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  throw	
  new	
  System.NotImplementedException();	
  
	
  	
  	
  }	
  
}
RED
Write enough to pass your
test
public	
  class	
  LifeRules	
  
{	
  
	
  	
  	
  public	
  static	
  CellState	
  GetNewState(CellState	
  currentState,	
  int	
  neighbourCount)	
  
	
  	
  	
  {	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  if	
  (currentState	
  ==	
  CellState.ALIVE	
  &&	
  neighbourCount	
  <	
  2)	
  
	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  return	
  currentState;	
  
	
  	
  	
  }	
  
}
GREEN
General Test Structure
Minimum Setup for Test (Given)
Invoke the event (When)
Verify assertions (Then)
Add Test for next story
[TestMethod]	
  
public	
  void	
  LiveCell_WithTwoOrThreeNeighbour_Survives()	
  
{	
  
	
  	
  	
  	
  //Given	
  
	
  	
  	
  	
  CellState	
  cellState	
  =	
  CellState.ALIVE;	
  
	
  	
  	
  	
  int	
  neighbourCount	
  =	
  3;	
  
	
  	
  	
  	
  //When	
  
	
  	
  	
  	
  CellState	
  result	
  =	
  LifeRules.GetNewState(cellState,	
  neighbourCount);	
  
	
  	
  	
  	
  //Then	
  
	
  	
  	
  	
  Assert.AreEqual(CellState.ALIVE,	
  result);	
  
}	
  
Add Implementation
public	
  class	
  LifeRules	
  
{	
  
	
  	
  	
  public	
  static	
  CellState	
  GetNewState(CellState	
  currentState,	
  int	
  neighbourCount)	
  
	
  	
  	
  {	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  if	
  (currentState	
  ==	
  CellState.ALIVE	
  &&	
  neighbourCount	
  <	
  2)	
  
	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  }	
  
if	
  (currentState	
  ==	
  CellState.ALIVE	
  &&	
  neighbourCount	
  >	
  3)	
  
	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  return	
  currentState;	
  
	
  	
  	
  }	
  
}
Add Test for two more stories
[TestMethod]	
  
public	
  void	
  LiveCell_WithMoreThanThreeNeighbour_Dies()	
  
{	
  
	
  	
  	
  	
  //Given	
  
	
  	
  	
  	
  CellState	
  cellState	
  =	
  CellState.ALIVE;	
  
	
  	
  	
  	
  	
  	
  	
  int	
  neighbourCount	
  =	
  4;	
  
	
  	
  	
  	
  //When	
  
	
  	
  	
  	
  CellState	
  result	
  =	
  LifeRules.GetNewState(cellState,	
  neighbourCount);	
  
	
  	
  	
  //Then	
  
	
  	
  	
  Assert.AreEqual(CellState.DEAD,	
  result);	
  
}	
  
[TestMethod]	
  
public	
  void	
  DeadCell_WithThreeNeighbour_Lives()	
  
{	
  
	
  	
  	
  	
  //Given	
  
	
  	
  	
  	
  CellState	
  cellState	
  =	
  CellState.DEAD;	
  
	
  	
  	
  	
  int	
  neighbourCount	
  =	
  3;	
  
	
  	
  	
  	
  //When	
  
	
  	
  	
  	
  CellState	
  result	
  =	
  LifeRules.GetNewState(cellState,	
  neighbourCount);	
  
	
  	
  	
  	
  //Then	
  
	
  	
  	
  	
  Assert.AreEqual(CellState.ALIVE,	
  result);	
  
}
Add remaining implementations
public	
  class	
  LifeRules	
  
{	
  
	
  	
  	
  	
  public	
  static	
  CellState	
  GetNewState(CellState	
  currentState,	
  int	
  neighbourCount)	
  
	
  	
  	
  	
  {	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (currentState	
  ==	
  CellState.ALIVE	
  &&	
  neighbourCount	
  <	
  2)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (currentState	
  ==	
  CellState.ALIVE	
  &&	
  neighbourCount	
  >	
  3)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (currentState	
  ==	
  CellState.DEAD	
  &&	
  neighbourCount	
  ==	
  3)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.ALIVE;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  currentState;	
  
	
  	
  	
  	
  }	
  
}
REFACTOR
Refactored Code
public	
  class	
  LifeRules	
  
{	
  
	
  	
  	
  	
  public	
  static	
  CellState	
  GetNewState(CellState	
  currentState,	
  int	
  neighbourCount)	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  switch	
  (currentState)	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  case	
  CellState.ALIVE:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (neighbourCount	
  <	
  2	
  ||	
  neighbourCount	
  >	
  3)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.DEAD;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  break;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  case	
  CellState.DEAD:	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (neighbourCount	
  ==	
  3)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  CellState.ALIVE;	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  break;	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  currentState;	
  
	
  	
  	
  	
  }	
  
}
Theme of TDD
FAIL
PASS
REFACTOR
Crux of TDD
• Analysing the minimalistic need of story and
implementing it in the cleanest way possible
• Design the code unit by unit
Benefits of TDD
• Deliver what is necessary.
• Helps take baby steps.
• System so developed does just what is required, no
more, no less.
• No future stories development (YAGNI - You ain’t
gonna need it).
• Better Code Coverage
TDD results in decoupled design
• Favours composition over inheritance.
• Small loosely coupled classes.
• Promotes coding to supertypes.
Benefits of TDD
• Increased confidence in developers working on test-
driven codebases
• Better code quality (in particular, less coupling and
higher cohesion)
• Improved maintainability and changeability of
codebases
• Ability to refactor without fear of breaking things
Benefits of TDD
• Test act as a "living specification" of expected behaviour
• Smaller production codebases with more simple designs
• Easier detection of flaws in the interactions between
objects
• Reduced need for manual testing
• Faster feedback loop for discovering whether an
implementation is correct
Removes Code Smells
• Duplicate Code
• Long methods
• Classes with too much code
• Lot of unused code
• Too many private methods
• Excessive Overloading
Costs of TDD
Claim - Slower per-feature development work because tests take
a lot of time to write
Rebut - Prevents speculative design and living with debugger.
Claim - Tests are code in themselves, require maintenance and
that’s overhead.
Rebut - Better than maintaining bug list.
Claim - Effectiveness is highly dependent on experience/
discipline of dev team.
Rebut - TDD is not a silver bullet. Just like with any skill, one
needs time to hone their skills.
Good Test are
• Small
• Expressive
• Maintainable
• Should execute fast
• talk Domain language
• must be thorough
• automated
• repeatable
Flavours of Test
• Unit Tests
• Integration Tests
• End to End Tests
Unit testing frameworks
• JUnit/TestNG for Java
• NUnit/MsTest for C#
• Minitest/TestUnit for Ruby
• pyUnit/unittest for Python
Thank you

More Related Content

Similar to Test Driven Development (TDD)

J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드ksain
 
Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Sergio Arroyo
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 
Advance unittest
Advance unittestAdvance unittest
Advance unittestReza Arbabi
 
More topics on Java
More topics on JavaMore topics on Java
More topics on JavaAhmed Misbah
 
Using Formal Methods to Create Instruction Set Architectures
Using Formal Methods to Create Instruction Set ArchitecturesUsing Formal Methods to Create Instruction Set Architectures
Using Formal Methods to Create Instruction Set ArchitecturesDVClub
 
Cryptographic Hash Function using Cellular Automata
Cryptographic Hash Function using Cellular AutomataCryptographic Hash Function using Cellular Automata
Cryptographic Hash Function using Cellular AutomataEditor IJCATR
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
CS5393-Korat_Mittal_Akshay_ProjReport
CS5393-Korat_Mittal_Akshay_ProjReportCS5393-Korat_Mittal_Akshay_ProjReport
CS5393-Korat_Mittal_Akshay_ProjReportAkshay Mittal
 
Reply if you have any doubts.public class Life {    public stati.pdf
Reply if you have any doubts.public class Life {    public stati.pdfReply if you have any doubts.public class Life {    public stati.pdf
Reply if you have any doubts.public class Life {    public stati.pdfnareshsonyericcson
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
Java Design Patterns: The State Pattern
Java Design Patterns: The State PatternJava Design Patterns: The State Pattern
Java Design Patterns: The State PatternAntony Quinn
 
Learn How to Develop a Distributed Game of Life with DDS
Learn How to Develop a Distributed Game of Life with DDSLearn How to Develop a Distributed Game of Life with DDS
Learn How to Develop a Distributed Game of Life with DDSReal-Time Innovations (RTI)
 

Similar to Test Driven Development (TDD) (20)

J unit스터디슬라이드
J unit스터디슬라이드J unit스터디슬라이드
J unit스터디슬라이드
 
JUnit PowerUp
JUnit PowerUpJUnit PowerUp
JUnit PowerUp
 
Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...Some testing - Everything you should know about testing to go with @pedro_g_s...
Some testing - Everything you should know about testing to go with @pedro_g_s...
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Advance unittest
Advance unittestAdvance unittest
Advance unittest
 
More topics on Java
More topics on JavaMore topics on Java
More topics on Java
 
Using Formal Methods to Create Instruction Set Architectures
Using Formal Methods to Create Instruction Set ArchitecturesUsing Formal Methods to Create Instruction Set Architectures
Using Formal Methods to Create Instruction Set Architectures
 
Cryptographic Hash Function using Cellular Automata
Cryptographic Hash Function using Cellular AutomataCryptographic Hash Function using Cellular Automata
Cryptographic Hash Function using Cellular Automata
 
Ifi7107 lesson4
Ifi7107 lesson4Ifi7107 lesson4
Ifi7107 lesson4
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
CS5393-Korat_Mittal_Akshay_ProjReport
CS5393-Korat_Mittal_Akshay_ProjReportCS5393-Korat_Mittal_Akshay_ProjReport
CS5393-Korat_Mittal_Akshay_ProjReport
 
IPA Fall Days 2019
 IPA Fall Days 2019 IPA Fall Days 2019
IPA Fall Days 2019
 
Reply if you have any doubts.public class Life {    public stati.pdf
Reply if you have any doubts.public class Life {    public stati.pdfReply if you have any doubts.public class Life {    public stati.pdf
Reply if you have any doubts.public class Life {    public stati.pdf
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Java Design Patterns: The State Pattern
Java Design Patterns: The State PatternJava Design Patterns: The State Pattern
Java Design Patterns: The State Pattern
 
Learn How to Develop a Distributed Game of Life with DDS
Learn How to Develop a Distributed Game of Life with DDSLearn How to Develop a Distributed Game of Life with DDS
Learn How to Develop a Distributed Game of Life with DDS
 
Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 

Recently uploaded (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 

Test Driven Development (TDD)

  • 2. What TDD is not • is not about Testing • is not Test Last
  • 3. What TDD is is about evolving the design of the system through Tests.
  • 4. Game Of Life - Stories 1. Any live cell with fewer than two live neighbours dies, as if caused by under-population. 2. Any live cell with two or three live neighbours lives on to the next generation. 3. Any live cell with more than three live neighbours dies, as if by overcrowding. 4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
  • 5. Specify what test should do [TestClass]          public  class  GameOfLifeTest          {                  [TestMethod]                  public  void  LiveCell_WithLessThanTwoNeighbour_Dies()                  {                          //Given                          CellState  cellState  =  CellState.ALIVE;                          int  neighbourCount  =  1;                          //When                          CellState  result  =  LifeRules.GetNewState(cellState,  neighbourCount);                          //Then                          Assert.AreEqual(CellState.DEAD,  result);                  }          }   }
  • 6. Write enough to compile public  class  LifeRules   {        public  static  CellState  GetNewState(CellState  cellState,  int  neighbourCount)        {              throw  new  System.NotImplementedException();        }   }
  • 7. RED
  • 8. Write enough to pass your test public  class  LifeRules   {        public  static  CellState  GetNewState(CellState  currentState,  int  neighbourCount)        {                      if  (currentState  ==  CellState.ALIVE  &&  neighbourCount  <  2)                {                        return  CellState.DEAD;                }                return  currentState;        }   }
  • 10. General Test Structure Minimum Setup for Test (Given) Invoke the event (When) Verify assertions (Then)
  • 11. Add Test for next story [TestMethod]   public  void  LiveCell_WithTwoOrThreeNeighbour_Survives()   {          //Given          CellState  cellState  =  CellState.ALIVE;          int  neighbourCount  =  3;          //When          CellState  result  =  LifeRules.GetNewState(cellState,  neighbourCount);          //Then          Assert.AreEqual(CellState.ALIVE,  result);   }  
  • 12. Add Implementation public  class  LifeRules   {        public  static  CellState  GetNewState(CellState  currentState,  int  neighbourCount)        {                      if  (currentState  ==  CellState.ALIVE  &&  neighbourCount  <  2)                {                        return  CellState.DEAD;                }   if  (currentState  ==  CellState.ALIVE  &&  neighbourCount  >  3)            {                      return  CellState.DEAD;                }                return  currentState;        }   }
  • 13. Add Test for two more stories [TestMethod]   public  void  LiveCell_WithMoreThanThreeNeighbour_Dies()   {          //Given          CellState  cellState  =  CellState.ALIVE;                int  neighbourCount  =  4;          //When          CellState  result  =  LifeRules.GetNewState(cellState,  neighbourCount);        //Then        Assert.AreEqual(CellState.DEAD,  result);   }   [TestMethod]   public  void  DeadCell_WithThreeNeighbour_Lives()   {          //Given          CellState  cellState  =  CellState.DEAD;          int  neighbourCount  =  3;          //When          CellState  result  =  LifeRules.GetNewState(cellState,  neighbourCount);          //Then          Assert.AreEqual(CellState.ALIVE,  result);   }
  • 14. Add remaining implementations public  class  LifeRules   {          public  static  CellState  GetNewState(CellState  currentState,  int  neighbourCount)          {                        if  (currentState  ==  CellState.ALIVE  &&  neighbourCount  <  2)                  {                          return  CellState.DEAD;                  }                  if  (currentState  ==  CellState.ALIVE  &&  neighbourCount  >  3)                  {                          return  CellState.DEAD;                  }                  if  (currentState  ==  CellState.DEAD  &&  neighbourCount  ==  3)                  {                          return  CellState.ALIVE;                  }                  return  currentState;          }   }
  • 16. Refactored Code public  class  LifeRules   {          public  static  CellState  GetNewState(CellState  currentState,  int  neighbourCount)          {                  switch  (currentState)                  {                                  case  CellState.ALIVE:                                          if  (neighbourCount  <  2  ||  neighbourCount  >  3)                                                  return  CellState.DEAD;                                  break;                                  case  CellState.DEAD:                                          if  (neighbourCount  ==  3)                                                  return  CellState.ALIVE;                                  break;                  }                  return  currentState;          }   }
  • 18. Crux of TDD • Analysing the minimalistic need of story and implementing it in the cleanest way possible • Design the code unit by unit
  • 19. Benefits of TDD • Deliver what is necessary. • Helps take baby steps. • System so developed does just what is required, no more, no less. • No future stories development (YAGNI - You ain’t gonna need it). • Better Code Coverage
  • 20. TDD results in decoupled design • Favours composition over inheritance. • Small loosely coupled classes. • Promotes coding to supertypes.
  • 21. Benefits of TDD • Increased confidence in developers working on test- driven codebases • Better code quality (in particular, less coupling and higher cohesion) • Improved maintainability and changeability of codebases • Ability to refactor without fear of breaking things
  • 22. Benefits of TDD • Test act as a "living specification" of expected behaviour • Smaller production codebases with more simple designs • Easier detection of flaws in the interactions between objects • Reduced need for manual testing • Faster feedback loop for discovering whether an implementation is correct
  • 23. Removes Code Smells • Duplicate Code • Long methods • Classes with too much code • Lot of unused code • Too many private methods • Excessive Overloading
  • 24. Costs of TDD Claim - Slower per-feature development work because tests take a lot of time to write Rebut - Prevents speculative design and living with debugger. Claim - Tests are code in themselves, require maintenance and that’s overhead. Rebut - Better than maintaining bug list. Claim - Effectiveness is highly dependent on experience/ discipline of dev team. Rebut - TDD is not a silver bullet. Just like with any skill, one needs time to hone their skills.
  • 25. Good Test are • Small • Expressive • Maintainable • Should execute fast • talk Domain language • must be thorough • automated • repeatable
  • 26. Flavours of Test • Unit Tests • Integration Tests • End to End Tests
  • 27. Unit testing frameworks • JUnit/TestNG for Java • NUnit/MsTest for C# • Minitest/TestUnit for Ruby • pyUnit/unittest for Python