SlideShare une entreprise Scribd logo
1  sur  10
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

Contenu connexe

Tendances

Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done RightBrian 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 MistakesRoy 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 ScratchRoy 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 buildAndrei Sebastian Cîmpean
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD DemonstratedAlan Christensen
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Clean tests
Clean testsClean tests
Clean testsAgileee
 
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 CodeFlorin Coros
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš 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 BankowskiAgileee
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh 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 developmentStephen 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 - RefactoringDiaa Al-Salehi
 

Tendances (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
 

En vedette

AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit TestingPrince Norin
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.jsRotem Tamir
 
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 TestingDavid Berliner
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 

En vedette (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
 

Similaire à Improve Server Testing

Unit Testing
Unit TestingUnit Testing
Unit TestingAdam Birr
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'tsPekka Klärck
 
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 99designslachlandonald
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practicesBill Buchan
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
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 TestingEyal 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 HoleNoam Kfir
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with LaravelTyler Johnston
 
Level Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingLevel Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingGordon 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 applicationsOrtus Solutions, Corp
 

Similaire à Improve Server 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
 

Plus de Adam Birr

Church Websites
Church WebsitesChurch Websites
Church WebsitesAdam 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 BirrAdam Birr
 
Stages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhoodStages of spiritual growth - spiritual childhood
Stages of spiritual growth - spiritual childhoodAdam Birr
 
Stages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancyStages of spiritual growth - spiritual infancy
Stages of spiritual growth - spiritual infancyAdam Birr
 
Real life discipleship - intro
Real life discipleship  - introReal life discipleship  - intro
Real life discipleship - introAdam 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 ChristAdam Birr
 
With your Soul
With your SoulWith your Soul
With your SoulAdam 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 websiteAdam Birr
 
Be Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of ChristBe Merciful - Glasgow church of Christ
Be Merciful - Glasgow church of ChristAdam Birr
 
Gospel legacy - Paolo Ugolini
Gospel legacy - Paolo UgoliniGospel legacy - Paolo Ugolini
Gospel legacy - Paolo UgoliniAdam Birr
 
Gospel Unity - Paolo Ugolini
Gospel Unity - Paolo UgoliniGospel Unity - Paolo Ugolini
Gospel Unity - Paolo UgoliniAdam Birr
 
Gospel purity - Paolo Ugolini
Gospel purity - Paolo UgoliniGospel purity - Paolo Ugolini
Gospel purity - Paolo UgoliniAdam Birr
 
Deploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone AppsDeploying Enterprise Cordova Windows Phone Apps
Deploying Enterprise Cordova Windows Phone AppsAdam 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 UgoliniAdam Birr
 
Ephesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessingEphesians 1 - every spiritual blessing
Ephesians 1 - every spiritual blessingAdam Birr
 
Coversion of Saul
Coversion of SaulCoversion of Saul
Coversion of SaulAdam Birr
 
The grace of salvation
The grace of salvationThe grace of salvation
The grace of salvationAdam Birr
 
What is Truth? - by John Oakes
What is Truth? - by John OakesWhat is Truth? - by John Oakes
What is Truth? - by John OakesAdam Birr
 
The Case For Christ
The Case For ChristThe Case For Christ
The Case For ChristAdam Birr
 

Plus de 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
 

Dernier

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Dernier (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 

Improve Server 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