Anyone who knows me will tell you I am crazy about three things: Umbraco; Sitecore; and Test Driven / Behaviour Driven Development.
Starting out as a developer was very tough. Glass Mapper was in its infancy and I remember developers often remarking “Unit testing is hard because there is no way of isolating the Sitecore context”. While I can now empathise, I no longer have to endure, as I can use a framework called FakeDb to solve this problem. It’s fantastic!
What is FakeDB?
It enables for creation and manipulation of Sitecore content in memory.
Why is this good?
Well, it allows you to quickly and cleanly unit test functionality that interacts with the Sitecore context.
FakeDb.Serialization, an extension to the FakeDb framework that allows you to deserialize data in your unit tests. If we assume that your Sitecore items are serialized in some manner, then we can use this extension to test against our actual Sitecore data. I will be experimenting with this idea in a further blog post but a good example is given here, by Robin Hermanussen.
What else can it do?
For the purpose of the article I won’t bother to show you how to use FakeDb as there are plenty of examples available on GitHub.
PM> Install-Package Sitecore.FakeDb
To stay up-to-date with the latest tech news and views, be sure to check out our weekly tech round-up posts - and sign up to our mailing list to have them delivered direct to your inbox.