Top Banner
Organized by the Community, for the Community. TEST DRIVEN SITECORE Dan Solovay Sitecore MVP Lead Architect at XCentium
22

Dan Solovay - Test Driven Sitecore - SUGCON

Apr 16, 2017

Download

Technology

SUGCON
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community.

TEST DRIVEN SITECORE

Dan SolovaySitecore MVPLead Architect at XCentium

Page 2: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 3: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 3

MORE ISOLATION

Sitecore Integration Testing

Sitecore.FakeDB

Glass.Mapper + Autofac

SUGCON NORTH AMERICA 2015

Page 4: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 4

MORE FLEXIBILITY

SUGCON NORTH AMERICA 2015

Page 5: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 5SUGCON NORTH AMERICA 2015

TEST DRIVEN DEVELOPMENT

Page 6: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 7: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 8: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 8SUGCON NORTH AMERICA 2015

UNIT ANDINTEGRATIONTESTING

Page 9: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 10: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 11: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 11SUGCON NORTH AMERICA 2015

TOOLS

Page 12: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 13: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 13SUGCON NORTH AMERICA 2015

TESTING SITECORE

Page 14: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 15: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 16: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 17: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 17SUGCON NORTH AMERICA 2015

NEXT STEPS

Page 18: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 18

BENEFITS

• Encourages focus• Creates confidence• Drives good design

SUGCON NORTH AMERICA 2015

Page 19: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community. 19

CHALLENGES

• Hard to learn new habits• Team buy in• Finding time

SUGCON NORTH AMERICA 2015

Page 20: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 21: Dan Solovay - Test Driven Sitecore - SUGCON

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

Page 22: Dan Solovay - Test Driven Sitecore - SUGCON

Organized by the Community, for the Community.SUGCON NORTH AMERICA 2015

Thanks!

@DanSolovay

bit.ly/tddlinks