Successfully reported this slideshow.
Your SlideShare is downloading. ×

Test-Driven Sitecore

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 36 Ad

More Related Content

Slideshows for you (20)

Viewers also liked (16)

Advertisement

Similar to Test-Driven Sitecore (20)

Recently uploaded (20)

Advertisement

Test-Driven Sitecore

  1. 1. Test-Driven Sitecore
  2. 2. @DanSolovay Sitecore Practice Lead at Velir MVP x 3 dansolovay.com velir.com/blog
  3. 3. 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
  4. 4. 1. Unit Testing and Test- Driven Development
  5. 5. What is a Unit Test? • Can be automated • In memory (no DB or File access) • Consistent & Fast • Single Logical Concept
  6. 6. Unit Testing is a Waste of Time …unless you plan to make changes to your code.
  7. 7. Unit Tests Let You… • Change code with confidence • Refactor • Keep code simple • Work well with others
  8. 8. Test-Driven Development • RED: Make a failing test. • GREEN: Make it pass. • REFACTOR: Make it clean.
  9. 9. This is stupid! "It's going to slow me down, it's a waste of time and effort, it will just break my flow."
  10. 10. 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
  11. 11. Calculator Kata A classic exercise to learn TDD bit.ly/tdd-kata
  12. 12. Recap • Code is always working • RED: Add functionality • GREEN: Add design • Practice, practice, practice
  13. 13. 2. Isolating Dependencies
  14. 14. Isolation How do I keep out the real world? • Talk to interfaces • Wire with AutoFac • Fake with NSubstitute
  15. 15. AutoFac • Constructor injection • Interfaces  Classes • Code to abstractions
  16. 16. NSubstitute • Create fakes from interfaces • Script output • Verify input
  17. 17. Recap • MVC + AutoFac: Interfaces  Production Objects • NSubstitute: Interfaces  Fakes
  18. 18. 3. Isolating Sitecore
  19. 19. Sitecore and Testability Sitecore items are FAT objects • Knowledge of database • Hard to “new up” • God-like Static methods
  20. 20. Glass Mapper • Injects items into light objects • Plays well with AutoFac & MVC • Code Gen option Documentation: http://glass.lu
  21. 21. Sitecore.FakeDB • Creates fake Items • Can fake: • Hierarchies • Templates • Security • Still in Development Github: bit.ly/FakeDB
  22. 22. Recap • Glass for isolating Sitecore • Sitecore.FakeDB for legacy code
  23. 23. 4. Testing Sitecore Itself
  24. 24. Codeflood Test Runner • Available at CodeFlood.net • Useful for testing Sitecore behavior
  25. 25. Recap • Integration tests talk to real things • Use for testing Sitecore tools • Use unit tests to build logic
  26. 26. 5. How to Get Started
  27. 27. 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.
  28. 28. NSubstitute ReSharper NCrunch XUnit?
  29. 29. To Learn More • My talk videos: bit.ly/tdd-videos • String Calculator: bit.ly/tdd-kata • Alistair Deneys’ blog: bit.ly/sitecore-testing
  30. 30. Photo Credits Clock: © littlenelly, Flickr Traffic Light: © Niels Sienaert, Flickr Lighthouse: © Dennis Jarvis, Flickr Screwdriver: © Gal, Flickr Dan: © Chris Brady, Velir
  31. 31. Thanks… @DanSolovay @Velir

×