SlideShare a Scribd company logo
Software
               Develop
Engineers




QA            Manual Tests




                                      Testin
Test        Automated Tests   Tools     g
Engineers
                                      Magic
1) Do work in constructor.
   Work in the constructor such as:
    creating/initializing collaborators,
    communicating with other services,
   Logic to set up its own state removes seams
    needed for testing, forcing subclasses/mocks
    to inherit unwanted behavior. Too much work
    in the constructor prevents instantiation or
    altering collaborators in the test.
   The LawOfDemeter specifies a style guideline:
    "Only talk to your immediate friends."

   Objects are passed in but never used directly
    (only used to get access to other objects)
   JUnit is a unit testing framework for the Java
    programming language. JUnit has been
    important in the development of test-driven
    development.
import org.junit.*;
public class TestFoobar{
@Before public void setUp() throws Exception {}
@Test public void testSomething () {
//This piece will use asserts to verify.
}
@After public void tearDown() throws
  Exception{}
}
Before: Hard to Test                 // An attempted test that
                                     becomes pretty hard
/* Basic new operators called        class HouseTest extends TestCase
directly in the class constructor.   {
(Forever preventing a seam to
create different kitchen and         public void testThisIsReallyHard() {
bedroom collaborators). */
                                     House house = new House();
class House {                        /* I'm stuck with those Kitchen
Kitchen kitchen = new Kitchen();     and Bedroom objects created in
Bedroom bedroom;                     the constructor. */
House() {                            }
bedroom = new Bedroom();             }
}

More Related Content

What's hot

Junit
JunitJunit
Constructor
ConstructorConstructor
Constructor
Bastin Rogers
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
Aktuğ Urun
 
Cactus in container_unit_test_framework
Cactus in container_unit_test_frameworkCactus in container_unit_test_framework
Cactus in container_unit_test_framework
Kenan Sevindik
 
Test ng
Test ngTest ng
Test ng
fbenault
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
Pranalee Rokde
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3
Vasil Remeniuk
 
Java - Singleton Pattern
Java - Singleton PatternJava - Singleton Pattern
Java - Singleton Pattern
Charles Casadei
 
Junit
JunitJunit
Complementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an ExampleComplementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an Example
PVS-Studio
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
Büşra İçöz
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
Calculon
CalculonCalculon
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 
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
 
Intro to junit
Intro to junitIntro to junit
Intro to junit
Rakesh Srivastava
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
Gousalya Ramachandran
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Devvrat Shukla
 
Test doubles
Test doublesTest doubles

What's hot (20)

Junit
JunitJunit
Junit
 
Constructor
ConstructorConstructor
Constructor
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
Cactus in container_unit_test_framework
Cactus in container_unit_test_frameworkCactus in container_unit_test_framework
Cactus in container_unit_test_framework
 
Test ng
Test ngTest ng
Test ng
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3
 
Java - Singleton Pattern
Java - Singleton PatternJava - Singleton Pattern
Java - Singleton Pattern
 
Junit
JunitJunit
Junit
 
Complementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an ExampleComplementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an Example
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Calculon
CalculonCalculon
Calculon
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
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!
 
Intro to junit
Intro to junitIntro to junit
Intro to junit
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Test doubles
Test doublesTest doubles
Test doubles
 

Viewers also liked

RESUMS DE LA LLEGENDA "La primera mata d'arròs"
RESUMS DE LA LLEGENDA "La primera mata d'arròs"RESUMS DE LA LLEGENDA "La primera mata d'arròs"
RESUMS DE LA LLEGENDA "La primera mata d'arròs"Maria Josep Casals Ricart
 
Actes comitè verd 2015 16 1r trimestre
Actes comitè verd 2015 16 1r trimestreActes comitè verd 2015 16 1r trimestre
Actes comitè verd 2015 16 1r trimestre
Maria Josep Casals Ricart
 
less freamwork
less freamworkless freamwork
less freamworkkafshduzak
 
Ci fitxes de formes geomètriques de la natura
Ci fitxes de formes geomètriques de la naturaCi fitxes de formes geomètriques de la natura
Ci fitxes de formes geomètriques de la naturaMaria Josep Casals Ricart
 
less freamwork
less freamworkless freamwork
less freamwork
kafshduzak
 
Proposta deures estiu 2015 16
Proposta deures estiu 2015 16Proposta deures estiu 2015 16
Proposta deures estiu 2015 16
Maria Josep Casals Ricart
 
PDF Valldemossa (Mallorca)
PDF Valldemossa (Mallorca)PDF Valldemossa (Mallorca)
PDF Valldemossa (Mallorca)
Maria Josep Casals Ricart
 
Maintaining Customer Loyalty
Maintaining Customer LoyaltyMaintaining Customer Loyalty
Maintaining Customer Loyalty
lanka999
 
Kim Peterson's Visual Resume
Kim Peterson's Visual ResumeKim Peterson's Visual Resume
Kim Peterson's Visual Resume
petersonks
 
Chapter7 Innovative Education
Chapter7 Innovative EducationChapter7 Innovative Education
Chapter7 Innovative Education
OopAib Rattanachodpradit
 
მექანიკური მუშაობა
მექანიკური მუშაობამექანიკური მუშაობა
მექანიკური მუშაობაlikasoch
 

Viewers also liked (17)

RESUMS DE LA LLEGENDA "La primera mata d'arròs"
RESUMS DE LA LLEGENDA "La primera mata d'arròs"RESUMS DE LA LLEGENDA "La primera mata d'arròs"
RESUMS DE LA LLEGENDA "La primera mata d'arròs"
 
Article 8
Article  8Article  8
Article 8
 
Actes comitè verd 2015 16 1r trimestre
Actes comitè verd 2015 16 1r trimestreActes comitè verd 2015 16 1r trimestre
Actes comitè verd 2015 16 1r trimestre
 
less freamwork
less freamworkless freamwork
less freamwork
 
Article 8
Article  8Article  8
Article 8
 
Kajian tindakan
Kajian tindakanKajian tindakan
Kajian tindakan
 
Ci fitxes de formes geomètriques de la natura
Ci fitxes de formes geomètriques de la naturaCi fitxes de formes geomètriques de la natura
Ci fitxes de formes geomètriques de la natura
 
less freamwork
less freamworkless freamwork
less freamwork
 
Observem
Observem Observem
Observem
 
Proposta deures estiu 2015 16
Proposta deures estiu 2015 16Proposta deures estiu 2015 16
Proposta deures estiu 2015 16
 
PDF Valldemossa (Mallorca)
PDF Valldemossa (Mallorca)PDF Valldemossa (Mallorca)
PDF Valldemossa (Mallorca)
 
Llegenda la primera mata d'arròs
Llegenda la primera mata d'arròsLlegenda la primera mata d'arròs
Llegenda la primera mata d'arròs
 
Maintaining Customer Loyalty
Maintaining Customer LoyaltyMaintaining Customer Loyalty
Maintaining Customer Loyalty
 
Kim Peterson's Visual Resume
Kim Peterson's Visual ResumeKim Peterson's Visual Resume
Kim Peterson's Visual Resume
 
Chapter7 Innovative Education
Chapter7 Innovative EducationChapter7 Innovative Education
Chapter7 Innovative Education
 
Laporan hari guru 2013
Laporan hari guru 2013Laporan hari guru 2013
Laporan hari guru 2013
 
მექანიკური მუშაობა
მექანიკური მუშაობამექანიკური მუშაობა
მექანიკური მუშაობა
 

Similar to Writing testable code

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Anand Kumar Rajana
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
alessiopace
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
Ahmed Ehab AbdulAziz
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
gauravavam
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
markstory
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
OpenDaylight
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
Ólafur Andri Ragnarsson
 
A fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with ArquillianA fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with Arquillian
Vineet Reynolds
 
Software Testing
Software TestingSoftware Testing
Software Testing
AdroitLogic
 
Android testing
Android testingAndroid testing
Android testing
Sean Tsai
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
kjkleindorfer
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
Priya Sharma
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
FalafelSoftware
 
Design patterns
Design patternsDesign patterns
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
Mark Baker
 

Similar to Writing testable code (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
 
A fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with ArquillianA fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with Arquillian
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Android testing
Android testingAndroid testing
Android testing
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 

Recently uploaded

How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Diana Rendina
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 

Recently uploaded (20)

How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 

Writing testable code

  • 1.
  • 2. Software Develop Engineers QA Manual Tests Testin Test Automated Tests Tools g Engineers Magic
  • 3. 1) Do work in constructor.
  • 4. Work in the constructor such as: creating/initializing collaborators, communicating with other services,  Logic to set up its own state removes seams needed for testing, forcing subclasses/mocks to inherit unwanted behavior. Too much work in the constructor prevents instantiation or altering collaborators in the test.
  • 5. The LawOfDemeter specifies a style guideline: "Only talk to your immediate friends."  Objects are passed in but never used directly (only used to get access to other objects)
  • 6. JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development.
  • 7. import org.junit.*; public class TestFoobar{ @Before public void setUp() throws Exception {} @Test public void testSomething () { //This piece will use asserts to verify. } @After public void tearDown() throws Exception{} }
  • 8. Before: Hard to Test // An attempted test that becomes pretty hard /* Basic new operators called class HouseTest extends TestCase directly in the class constructor. { (Forever preventing a seam to create different kitchen and public void testThisIsReallyHard() { bedroom collaborators). */ House house = new House(); class House { /* I'm stuck with those Kitchen Kitchen kitchen = new Kitchen(); and Bedroom objects created in Bedroom bedroom; the constructor. */ House() { } bedroom = new Bedroom(); } }