Sunday, September 27, 2015

Test Driven Sitecore Links

I'm honored to be speaking at the SUGCON conference in New Orleans next Thursday on Test Driven Development with Sitecore.  Here are some links related to the talk.

Update:

Here's a video recording of the talk. Thanks to Chris Auer for recording this.

Test Driven Development

  • I learned Unit Testing from this book by Roy Osherove: https://www.manning.com/books/the-art-of-unit-testing-second-edition (well the first edition).  It stresses three concepts very well: add seams to your code to allow for tests, write your tests in a loosely specified way so they don't all fail at once, and write in memory unit tests.  It offers a classic definition of a unit test, also available here.
  • I've just started looking into Kent Beck's original book, but I'm finding a lot of promising stuff in there.  (I like going back to the classics.).  A few tidbits: "Write tests until paranoia turns into boredom."  He recently wrote on Quora about his original inspiration for TDD.
  • I just came upon this discussion of the relative strengths of Unit and Integration testing on Stack Overflow.  Key idea: integration tests show you something is wrong, Unit tests show you where it is wrong.
  • One of the hardest aspects of getting started is developing the "muscle memory" of writing tests for small bits of functionality at a time, getting a feeling for the rhythm of it, and gaining confidence that this will quickly grow complex features.  The Kata exercise on Roy's blog is a really good way to get started here.  As a workshop exercise, it works very well with Pair Programming Ping Pong.
  • I talk about Robert Martin as an exponent of the power of this technique. Here is a classic, if strongly phrased, vision of the Red/Green/Recycle flow, and a passionate defense of TDD, from Uncle Bob Martin, and a more recent article discussing the different levels of granularity.
  • So there was this TDD is Dead thing last year.  David Heinemeier Hansson's post, and the video debate with DHH, Kent Beck and Martin Fowler. Great stuff, very engaging.

Sitecore Integration Testing


  • The idea of testing Sitecore functionality from a browser application was proposed by Alistair Deneys in 2008.  His blog, and talks, continue to be a rich source of information on automated testing of Sitecore. https://adeneys.wordpress.com/category/testing/
  • In 2010, Mike Edwards showed it was possible to run unit tests from a console app if configuration was put in the correct locations.  
  • In order to get this to work you need to tell Sitecore to look for configuration files inside the project, since the code that locates App_Config will point it to c:\ if not run inside a web application.  I wrote a post recommending a technique (setting Sitecore.Context.IsUnitTesting to true) that does not work for Sitecore 8. Fortunately, an approach recommend by Dan Cruikshank still works (setting State.HttpRuntimeAppDomainAppPath to the project root).  My post is still useful for showing how to set up the AfterBuild step, which I learned, and tweaked a bit, from Alistair's writings. 

Sitecore Fake DB

  • The best source here is the github repository and wiki.  The range of features of this tool is extensive, and goes far beyond what I show in my talk. 

Unit Testing with Glass

Tools

  • The thinking behind XUnit. In a word, creating a new object for every test run gives better isolation.
  • Roy Osherove on why you should use NSubstituteor FakeItEasy over MOQ. 
  • NCrunch, the TDD power tool.  Costly, but will get you hooked on test coverage.  Instant feedback as you write code.

No comments:

Post a Comment