dan solovay - test driven sitecore - sugcon
Post on 16-Apr-2017
278 Views
Preview:
TRANSCRIPT
Organized by the Community, for the Community.
TEST DRIVEN SITECORE
Dan SolovaySitecore MVPLead Architect at XCentium
Organized by the Community, for the Community. 2
OVERVIEW
• What is TDD?• Unit or Integration tests?• Tools• Demo of Sitecore Integration Testing• Demo of Sitecore.FakeDB• Demo of Glass.Mapper + Autofac • How to get started with TDD?
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 3
MORE ISOLATION
Sitecore Integration Testing
Sitecore.FakeDB
Glass.Mapper + Autofac
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 6
AGILE ORIGINS OF TDD• Rediscovered by Kent
Beck• Extreme Programming
– Embrace change
through continuous feedback
• Popularized by Robert Martin– Author of SOLID
principles– “What if your code
always worked?”
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 7
THE TDD CYCLE
• RED– Right just enough code to fail
• GREEN– Right just enough code to pass
• REFACTOR– Improve design when everything is
working
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 8SUGCON NORTH AMERICA 2015
UNIT ANDINTEGRATIONTESTING
Organized by the Community, for the Community. 9
WHAT IS A UNIT TEST?• Automated• Full control / runs
in memory• Consistent & fast• Tests a single
logical concept• Readable &
maintainable• Trustworthy
SUGCON NORTH AMERICA 2015
Roy Osherove,Art of Unit Testing
Organized by the Community, for the Community. 10
INTEGRATION TESTS
• More fragile• Provide full system confidence• Shows different systems working
together
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 12
MY TOOLBOX
• XUNIT– Better separation of tests than NUNIT.
• NCRUNCH– Runs tests as you type.
• NSUBSTITUTE– Creates fake versions of interfaces in
tests.• AUTOFAC
– Creates real versions in production.SUGCON NORTH
AMERICA 2015
Organized by the Community, for the Community. 14
SITECORE INTEGRATION TESTING• Browser based
– More robust– Http Context available
• Class Library based– Works with Test Runners– Easier to automate
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 15
SITECORE FAKE DB• Developed by Sergey Shusliapin of
Sitecore Ukraine• Uses Sitecore DLLs, replaces data
layer• Tests Sitecore Items directly• No code changes required!
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 16
MAP SITECORE ITEMS
• Use object mapper like Glass • Use Dependency Injector like
Autofac• Your code does not talk directly to
Sitecore
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 18
BENEFITS
• Encourages focus• Creates confidence• Drives good design
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 19
CHALLENGES
• Hard to learn new habits• Team buy in• Finding time
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 20
SOLUTIONS
• Avoid all-or-nothing thinking– One, two hours of TDD per week
• Get involvement– Pair up, ask for input– Run a TDD Kata session
• Sell the value– Fast feedback– Flexible design
SUGCON NORTH AMERICA 2015
Organized by the Community, for the Community. 21
FEARLESS
If we have the tests we become fearless about making changes. If we see messy code, or an unclean structure, we can clean it without fear. Because of the tests, the code becomes malleable again. Because of the tests, software becomes soft again.
– Robert Martin, bit.ly/tdd3rulesSUGCON NORTH AMERICA 2015
top related