codeflood logo

Coffee => Coder => Code

Ramblings on code, Sitecore and stuff

Posts from 2016

Sitecore 8.2: Mock your Items

Back in January I wrote an article about how to Roll your own Sitecore Item, which showed how to create an in-memory Sitecore item for use in testing. The technique was quite limited and still required some small config entry to allow everything to work (to create a Database instance). Well, Sitecore 8.2 has finally made a reality what so many of us have prayed for, for so long. We can finally mock Items and Databases with Sitecore 8.2. Though, it’s probably not quite as simple as you might hope.

Sitecore Integration Testing Made Easy

A few years back, I uploaded a couple of short videos to YouTube to show how easy it can be to get started with testing your Sitecore solution. The approach shown in the videos uses my ASP.NET embedded test runner. I developed the first version of this test runner when I was first trying to test my own Sitecore projects, many years ago. The issue many developers face when trying to test their Sitecore solutions is trying to get the Sitecore code to run outside of a web/Sitecore context. What I managed to do with this test runner was flip the problem on it’s head; instead of trying to get the Sitecore code to work inside my unit test, I made my unit test work inside my Sitecore solution.

Trekroner Fort

If there were a Mecca for Sitecore developers, it would likely be this place. Trekroner Fort. This famous Danish landmark welcomed many fresh-faced Sitecore developers and users as the default desktop background in Sitecore version 7.x and prior.

Roll your own Sitecore Item

One of the most difficult aspects of unit testing against Sitecore is mocking Sitecore items. The Sitecore Item class is quite a complex class and it’s interface is not structured the way most mocking frameworks require. Mocking frameworks allow you to create dummy objects for use inside tests. But that’s not the only way to create dummy objects. One can always instantiate a class if the classes interface allows it. You might be surprised to learn that you can in fact create an instance of a Sitecore Item in your own code.