SlideShare a Scribd company logo
Unit Testing 
Improving our server side testing 
methods
The Problem – Summary of issues with 
server unit tests 
• Unit not well defined 
• Dependency on other classes 
• Small change breaks tests across several projects 
• Purpose not always obvious 
• Many tests only assert that the result is not null 
• Asserting guards – not expectations 
• Tests are not always easy to read 
• Poor naming conventions 
• Not always well structured 
• Dependencies on test superclasses 
• Not alone in these issues – companies fail in getting testing right
What is a Unit 
• A “Unit” is a java class 
• Most classes which perform operations should be unit tested 
• Exceptions:- 
• Model objects 
• DAO – persistence managers 
• Cover all methods and paths 
• Dependencies should be mocked 
• Mockito 
• PowerMockito
Why Unit Test? 
• Describes specification 
• Code maintainability 
• Improves the design of the code 
• Documents the code 
• Reduces bugs 
• Identifies regressive behaviour 
• Helps peer review process of code
DAMP vs DRY – Paradigm Shift 
• DAMP (Descriptive And Meaningful Phrases) 
• Useful for unit testing 
• Promotes the readability of the code 
• Prioritises readability over duplication of code 
• Duplication is usually localised 
• DRY (Don't repeat yourself) 
• Useful for production code 
• Remove duplication 
• Every concept has a single authoritative representation in code 
• Reduces risk of change if only in one place
DAMP vs DRY – Paradigm Shift 
“So, why is duplication more acceptable in tests? 
Tests often contain inherent duplication because they are testing the same thing 
over and over again, only with slightly different input values or setup code. 
However, unlike production code, this duplication is usually isolated only to the 
scenarios within a single test fixture/file. Because of this, the duplication is minimal 
and obvious, which means it poses less risk to the project than other types of 
duplication. 
Furthermore, removing this kind of duplication reduces the readability of the tests. 
The details that were previously duplicated in each test are now hidden away in 
some new method or class. To get the full picture of the test, you now have to 
mentally put all these pieces back together. 
Therefore, since test code duplication often carries less risk, and promotes 
readability, its easy to see how it is considered acceptable. 
As a principle, favour DRY in production code, favour DAMP in test code. While 
both are equally important, with a little wisdom you can tip the balance in your 
favour.” 
- Chris Edwards - Stackoverflow
What Unit Tests Should Look Like? 
• Each test should look as simple as possible 
• The name should be meaningful 
• If the name contains either “And” or “Or” – 
split the test into two tests 
• Split up tests which use if/else 
• Test only one thing per test 
• Variable names: camel case plain English – not 
abbreviations. 
• Avoid using literal values
What Unit Tests Should Look Like? (cont…) 
• Assert what we are expecting – not null pointers 
• Use builders to construct test data 
• Testing exceptions should be done with 
annotations 
e.g. @Test(expected = 
AirpointInternalException.class)and not 
using try/catch fail() 
• Don’t make over use of setup methods
What Unit Tests Should Look Like? (cont…) 
• Use a template to separate test setup, execution 
and exceptions. E.g.: 
// given 
Setup 
// when 
Do something 
// then 
assert
“Now this is not the end. It is not 
even the beginning of the end. But it 
is, perhaps, the end of the 
beginning.” 
- Winston Churchill 
Comments and Questions

More Related Content

What's hot

Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
Brian Fenton
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide
vitalipe
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove
 
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
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From Scratch
Roy Osherove
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
Andrei Sebastian Cîmpean
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
Alan Christensen
 
Unit testing
Unit testingUnit testing
Unit testing
DrSimoneDiCola
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
Richard Paul
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
Tricode (part of Dept)
 
Clean tests
Clean testsClean tests
Clean tests
Agileee
 
Good Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality CodeGood Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality Code
Florin Coros
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
Tomaš Maconko
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Agileee
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Sahar Nofal
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Ievgenii Katsan
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
Diaa Al-Salehi
 

What's hot (20)

Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
 
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)
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From Scratch
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
 
Clean tests
Clean testsClean tests
Clean tests
 
Good Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality CodeGood Unit Tests Ask For Quality Code
Good Unit Tests Ask For Quality Code
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
Volodymyr Prymakov and Vlada Benyukh Detailed manual estimation approach for ...
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 

Viewers also liked

AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
Prince Norin
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
JWORKS powered by Ordina
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
Sencha
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
David Berliner
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 

Viewers also liked (6)

AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 

Similar to Unit testing

Unit Testing
Unit TestingUnit Testing
Unit Testing
Adam Birr
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Md. Enamul Haque Chowdhury
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'ts
Pekka Klärck
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Avinash Kadam
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designs
lachlandonald
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
Ganesh Kondal
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
Xavi Hidalgo
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
Clean code
Clean codeClean code
Clean code
Simon Sönnby
 
Tdd
TddTdd
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
Alan Christensen
 
Unit testing
Unit testingUnit testing
Unit testing
princezzlove
 
Unit testing
Unit testingUnit testing
Unit testing
PiXeL16
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
SQALab
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
Eyal Kenig
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
Noam Kfir
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
Tyler Johnston
 
Level Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingLevel Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit Testing
Gordon Bockus
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
Ortus Solutions, Corp
 

Similar to Unit testing (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'ts
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designs
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
Clean code
Clean codeClean code
Clean code
 
Tdd
TddTdd
Tdd
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
Level Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingLevel Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit Testing
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 

More from Adam Birr

Church Websites
Church WebsitesChurch Websites
Church Websites
Adam Birr
 
Power of cleansing - Gospel of Mark 1 - Adam Birr
Power of cleansing - Gospel of Mark 1 - Adam BirrPower of cleansing - Gospel of Mark 1 - Adam Birr
Power of cleansing - Gospel of Mark 1 - Adam Birr
Adam Birr
 
Stages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhoodStages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhood
Adam Birr
 
Stages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancyStages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancy
Adam Birr
 
Real life discipleship - intro
Real life discipleship  - introReal life discipleship  - intro
Real life discipleship - intro
Adam Birr
 
You and Me forever - Glasgow Church of Christ
You and Me forever - Glasgow Church of ChristYou and Me forever - Glasgow Church of Christ
You and Me forever - Glasgow Church of Christ
Adam Birr
 
With your Soul
With your SoulWith your Soul
With your Soul
Adam Birr
 
Spirit of 2012 spark grant - This is Ruchill community website
Spirit of 2012 spark grant - This is Ruchill community websiteSpirit of 2012 spark grant - This is Ruchill community website
Spirit of 2012 spark grant - This is Ruchill community website
Adam Birr
 
Be Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of ChristBe Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of Christ
Adam Birr
 
Gospel legacy - Paolo Ugolini
Gospel legacy - Paolo UgoliniGospel legacy - Paolo Ugolini
Gospel legacy - Paolo Ugolini
Adam Birr
 
Gospel Unity - Paolo Ugolini
Gospel Unity - Paolo UgoliniGospel Unity - Paolo Ugolini
Gospel Unity - Paolo Ugolini
Adam Birr
 
Gospel purity - Paolo Ugolini
Gospel purity - Paolo UgoliniGospel purity - Paolo Ugolini
Gospel purity - Paolo Ugolini
Adam Birr
 
Deploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone AppsDeploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone Apps
Adam Birr
 
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
Adam Birr
 
Ephesians 2 - christ and relationships - Paolo Ugolini
Ephesians 2 - christ and relationships - Paolo UgoliniEphesians 2 - christ and relationships - Paolo Ugolini
Ephesians 2 - christ and relationships - Paolo Ugolini
Adam Birr
 
Ephesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessingEphesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessing
Adam Birr
 
Coversion of Saul
Coversion of SaulCoversion of Saul
Coversion of Saul
Adam Birr
 
The grace of salvation
The grace of salvationThe grace of salvation
The grace of salvation
Adam Birr
 
What is Truth? - by John Oakes
What is Truth? - by John OakesWhat is Truth? - by John Oakes
What is Truth? - by John Oakes
Adam Birr
 
The Case For Christ
The Case For ChristThe Case For Christ
The Case For Christ
Adam Birr
 

More from Adam Birr (20)

Church Websites
Church WebsitesChurch Websites
Church Websites
 
Power of cleansing - Gospel of Mark 1 - Adam Birr
Power of cleansing - Gospel of Mark 1 - Adam BirrPower of cleansing - Gospel of Mark 1 - Adam Birr
Power of cleansing - Gospel of Mark 1 - Adam Birr
 
Stages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhoodStages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhood
 
Stages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancyStages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancy
 
Real life discipleship - intro
Real life discipleship  - introReal life discipleship  - intro
Real life discipleship - intro
 
You and Me forever - Glasgow Church of Christ
You and Me forever - Glasgow Church of ChristYou and Me forever - Glasgow Church of Christ
You and Me forever - Glasgow Church of Christ
 
With your Soul
With your SoulWith your Soul
With your Soul
 
Spirit of 2012 spark grant - This is Ruchill community website
Spirit of 2012 spark grant - This is Ruchill community websiteSpirit of 2012 spark grant - This is Ruchill community website
Spirit of 2012 spark grant - This is Ruchill community website
 
Be Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of ChristBe Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of Christ
 
Gospel legacy - Paolo Ugolini
Gospel legacy - Paolo UgoliniGospel legacy - Paolo Ugolini
Gospel legacy - Paolo Ugolini
 
Gospel Unity - Paolo Ugolini
Gospel Unity - Paolo UgoliniGospel Unity - Paolo Ugolini
Gospel Unity - Paolo Ugolini
 
Gospel purity - Paolo Ugolini
Gospel purity - Paolo UgoliniGospel purity - Paolo Ugolini
Gospel purity - Paolo Ugolini
 
Deploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone AppsDeploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone Apps
 
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
Ephesians 2 3 - Reconciled with each other - Paolo Ugolini - Glasgow Church o...
 
Ephesians 2 - christ and relationships - Paolo Ugolini
Ephesians 2 - christ and relationships - Paolo UgoliniEphesians 2 - christ and relationships - Paolo Ugolini
Ephesians 2 - christ and relationships - Paolo Ugolini
 
Ephesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessingEphesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessing
 
Coversion of Saul
Coversion of SaulCoversion of Saul
Coversion of Saul
 
The grace of salvation
The grace of salvationThe grace of salvation
The grace of salvation
 
What is Truth? - by John Oakes
What is Truth? - by John OakesWhat is Truth? - by John Oakes
What is Truth? - by John Oakes
 
The Case For Christ
The Case For ChristThe Case For Christ
The Case For Christ
 

Recently uploaded

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
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
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 

Recently uploaded (20)

Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
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...
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 

Unit testing

  • 1. Unit Testing Improving our server side testing methods
  • 2. The Problem – Summary of issues with server unit tests • Unit not well defined • Dependency on other classes • Small change breaks tests across several projects • Purpose not always obvious • Many tests only assert that the result is not null • Asserting guards – not expectations • Tests are not always easy to read • Poor naming conventions • Not always well structured • Dependencies on test superclasses • Not alone in these issues – companies fail in getting testing right
  • 3. What is a Unit • A “Unit” is a java class • Most classes which perform operations should be unit tested • Exceptions:- • Model objects • DAO – persistence managers • Cover all methods and paths • Dependencies should be mocked • Mockito • PowerMockito
  • 4. Why Unit Test? • Describes specification • Code maintainability • Improves the design of the code • Documents the code • Reduces bugs • Identifies regressive behaviour • Helps peer review process of code
  • 5. DAMP vs DRY – Paradigm Shift • DAMP (Descriptive And Meaningful Phrases) • Useful for unit testing • Promotes the readability of the code • Prioritises readability over duplication of code • Duplication is usually localised • DRY (Don't repeat yourself) • Useful for production code • Remove duplication • Every concept has a single authoritative representation in code • Reduces risk of change if only in one place
  • 6. DAMP vs DRY – Paradigm Shift “So, why is duplication more acceptable in tests? Tests often contain inherent duplication because they are testing the same thing over and over again, only with slightly different input values or setup code. However, unlike production code, this duplication is usually isolated only to the scenarios within a single test fixture/file. Because of this, the duplication is minimal and obvious, which means it poses less risk to the project than other types of duplication. Furthermore, removing this kind of duplication reduces the readability of the tests. The details that were previously duplicated in each test are now hidden away in some new method or class. To get the full picture of the test, you now have to mentally put all these pieces back together. Therefore, since test code duplication often carries less risk, and promotes readability, its easy to see how it is considered acceptable. As a principle, favour DRY in production code, favour DAMP in test code. While both are equally important, with a little wisdom you can tip the balance in your favour.” - Chris Edwards - Stackoverflow
  • 7. What Unit Tests Should Look Like? • Each test should look as simple as possible • The name should be meaningful • If the name contains either “And” or “Or” – split the test into two tests • Split up tests which use if/else • Test only one thing per test • Variable names: camel case plain English – not abbreviations. • Avoid using literal values
  • 8. What Unit Tests Should Look Like? (cont…) • Assert what we are expecting – not null pointers • Use builders to construct test data • Testing exceptions should be done with annotations e.g. @Test(expected = AirpointInternalException.class)and not using try/catch fail() • Don’t make over use of setup methods
  • 9. What Unit Tests Should Look Like? (cont…) • Use a template to separate test setup, execution and exceptions. E.g.: // given Setup // when Do something // then assert
  • 10. “Now this is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning.” - Winston Churchill Comments and Questions