SlideShare a Scribd company logo
Test-Driven
Sitecore
@DanSolovay
Sitecore Practice
Lead at Velir
MVP x 3
dansolovay.com
velir.com/blog
What’s the plan?
1. Unit Testing and Test-Driven Development
2. Isolating dependencies
3. Isolating Sitecore
4. Testing Sitecore itself
5. How to get started
1. Unit Testing and Test-
Driven Development
What is a Unit
Test?
• Can be automated
• In memory
(no DB or File access)
• Consistent & Fast
• Single Logical Concept
Unit Testing
is a Waste of
Time
…unless you plan
to make changes
to your code.
Unit Tests Let You…
• Change code with confidence
• Refactor
• Keep code simple
• Work well with others
Test-Driven
Development
• RED: Make a failing test.
• GREEN: Make it pass.
• REFACTOR: Make it clean.
This is stupid!
"It's going to slow me down, it's a
waste of time and effort, it will just
break my flow."
However…
Imagine if you walked into a room full of
people working this way. A minute ago, all
of their code worked.
Robert Martin, The Three Rules of TDD
bit.ly/tdd3rules
Calculator Kata
A classic exercise to learn TDD
bit.ly/tdd-kata
Test-Driven Sitecore
Recap
• Code is always working
• RED: Add functionality
• GREEN: Add design
• Practice, practice, practice
2. Isolating
Dependencies
Isolation
How do I keep out the real world?
• Talk to interfaces
• Wire with AutoFac
• Fake with NSubstitute
AutoFac
• Constructor injection
• Interfaces  Classes
• Code to abstractions
NSubstitute
• Create fakes from interfaces
• Script output
• Verify input
Test-Driven Sitecore
Recap
• MVC + AutoFac:
Interfaces  Production Objects
• NSubstitute:
Interfaces  Fakes
3. Isolating Sitecore
Sitecore and Testability
Sitecore items are FAT objects
• Knowledge of database
• Hard to “new up”
• God-like Static methods
Glass Mapper
• Injects items into light objects
• Plays well with AutoFac & MVC
• Code Gen option
Documentation: http://glass.lu
Test-Driven Sitecore
Sitecore.FakeDB
• Creates fake Items
• Can fake:
• Hierarchies
• Templates
• Security
• Still in Development
Github: bit.ly/FakeDB
Test-Driven Sitecore
Recap
• Glass for isolating Sitecore
• Sitecore.FakeDB for legacy code
4. Testing Sitecore Itself
Codeflood
Test Runner
• Available at
CodeFlood.net
• Useful for testing
Sitecore behavior
Test-Driven Sitecore
Recap
• Integration tests talk to real things
• Use for testing Sitecore tools
• Use unit tests to build logic
5. How to Get Started
Some Practical Tips
• Start small. One hour a week.
• Pair up.
• Keep tests clean.
• Keep tests passing.
• Do a Kata workshop.
• Do TDD Ping Pong.
NSubstitute
ReSharper
NCrunch
XUnit?
To Learn More
• My talk videos: bit.ly/tdd-videos
• String Calculator: bit.ly/tdd-kata
• Alistair Deneys’ blog: bit.ly/sitecore-testing
Photo Credits
Clock:
© littlenelly, Flickr
Traffic Light:
© Niels Sienaert, Flickr
Lighthouse:
© Dennis Jarvis, Flickr
Screwdriver:
© Gal, Flickr
Dan:
© Chris Brady, Velir
Thanks…
@DanSolovay
@Velir

More Related Content

PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
PPTX
How to make your functional tests really quick
PDF
Architecture of automated test cases for legacy applications
PDF
Selenium Best Practices with Jason Huggins
PPTX
Unit testing share point
PDF
Introduction to jest
PPTX
Saving Time By Testing With Jest
PDF
The Cowardly Test-o-Phobe's Guide To Testing
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
How to make your functional tests really quick
Architecture of automated test cases for legacy applications
Selenium Best Practices with Jason Huggins
Unit testing share point
Introduction to jest
Saving Time By Testing With Jest
The Cowardly Test-o-Phobe's Guide To Testing

What's hot (20)

PDF
How to Use Selenium, Successfully
PPT
Next generation frontend tooling
PPTX
Cypress workshop for JSFoo 2019
KEY
Enterprise Strength Mobile JavaScript
PPTX
Protractor training
PPTX
Automated Acceptance Testing from Scratch
PDF
How To Use Selenium Successfully
KEY
WTF TDD?
PDF
Practical Tips & Tricks for Selenium Test Automation
PDF
Agile Testing
PDF
Continuous Testing Meets the Classroom at Code.org
PPTX
Beyond the Release: CI That Transforms Organizations
PPTX
Breaking Dependencies to Allow Unit Testing
PDF
Testing Code.org's Interactive CS Curriculum
PPTX
Introduction to cypress in Angular (Chinese)
PDF
How To Use Selenium Successfully
PDF
Getting Started with Selenium
PDF
AngularJS and Protractor
PDF
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
PPTX
Architecting, testing and developing an mvc application
How to Use Selenium, Successfully
Next generation frontend tooling
Cypress workshop for JSFoo 2019
Enterprise Strength Mobile JavaScript
Protractor training
Automated Acceptance Testing from Scratch
How To Use Selenium Successfully
WTF TDD?
Practical Tips & Tricks for Selenium Test Automation
Agile Testing
Continuous Testing Meets the Classroom at Code.org
Beyond the Release: CI That Transforms Organizations
Breaking Dependencies to Allow Unit Testing
Testing Code.org's Interactive CS Curriculum
Introduction to cypress in Angular (Chinese)
How To Use Selenium Successfully
Getting Started with Selenium
AngularJS and Protractor
Selenium Tips & Tricks, presented at the Tel Aviv Selenium Meetup
Architecting, testing and developing an mvc application
Ad

Viewers also liked (16)

PPT
Being a subject matter expert
ODP
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
PPTX
The Safety Net of Functional Web Testing
PDF
Sitecore 7: A developers quest to mastering unit testing
PPT
Darfur1
PPTX
What are the advantages of non functional testing
PPTX
Continuous Testing of eCommerce Apps
PPTX
The importance of non functional testing
PPTX
Non-functional Testing (NFT) Overview
PPT
Sample QBR Slides
PPT
Non Functional Testing
PPSX
PPTX
DevOps 101
PPTX
Quarterly Business Review Template - QBR Template - Customer Success Management
PPTX
Quarterly Business Review Template
PPTX
Testing web services
Being a subject matter expert
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
The Safety Net of Functional Web Testing
Sitecore 7: A developers quest to mastering unit testing
Darfur1
What are the advantages of non functional testing
Continuous Testing of eCommerce Apps
The importance of non functional testing
Non-functional Testing (NFT) Overview
Sample QBR Slides
Non Functional Testing
DevOps 101
Quarterly Business Review Template - QBR Template - Customer Success Management
Quarterly Business Review Template
Testing web services
Ad

Similar to Test-Driven Sitecore (20)

PPTX
A tale of 3 databases
PDF
Summit 16: Stop Writing Legacy Code!
PPTX
Testing with laravel
PDF
TDD and Related Techniques for Non Developers (2012)
PDF
I am afraid of no test! The power of BDD
PPTX
Writing better code: How the Netbeans IDE Helps you Write, Test and Debug Java
PPTX
Untying the Knots of Web Dev with Internet Explorer
PPTX
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
PPTX
How to write test in node.js
PDF
Automated testing in javascript
PDF
Behat bdd training (php) course slides pdf
PPTX
A Brief Introduction to Test-Driven Development
PPTX
Refactoring Legacy Code - true story
PPTX
Unit Testing and Tools
PPTX
BTV PHP - Building Fast Websites
PPTX
Reviewing CPAN modules
PDF
Two Scope of Django 1.6 Chapter 20 and 21
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
PDF
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
PDF
Building XWiki
A tale of 3 databases
Summit 16: Stop Writing Legacy Code!
Testing with laravel
TDD and Related Techniques for Non Developers (2012)
I am afraid of no test! The power of BDD
Writing better code: How the Netbeans IDE Helps you Write, Test and Debug Java
Untying the Knots of Web Dev with Internet Explorer
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
How to write test in node.js
Automated testing in javascript
Behat bdd training (php) course slides pdf
A Brief Introduction to Test-Driven Development
Refactoring Legacy Code - true story
Unit Testing and Tools
BTV PHP - Building Fast Websites
Reviewing CPAN modules
Two Scope of Django 1.6 Chapter 20 and 21
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Building XWiki

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Digital-Transformation-Roadmap-for-Companies.pptx

Test-Driven Sitecore