Sitecore Unit Testing is not a success?

2.3k views Asked by At

We have done research to Unit Testing in our company. In my company we make custom .NET, Sitefinity and especially Sitecore. We have made successfully Unit Tests for custom .NET and Sitefinity, but we could not really get to useful tests. For mocking we use Telerik JustMock and the build-in TestExplorer in Visual Studio. The reason for this was we had to mock to much and that led to useless tests almost. Actually Sitecore is a database with pages/content for each item.

Now we are going to invest time in a further research, but some experience with Unit Testing with Sitecore will be very useful. So here are my question:

  1. Are there more people who encountered this problem in their company?
  2. What approach did you choose in this situation? Or: what would you suggest be doing in our situation? Should we give up or can we get it working and in what way?

(I have already asked a question about Sitecore Unit Testing, but that was for a good tutorial how to do this: Unit Testing Sitecore using NUnit, serializing content; the answer of Shriroop was useful.)

4

There are 4 answers

2
Shriroop On BEST ANSWER

Unit Testing is always useful for anything that is written in C# (or should I say in OO Language).

Please don't give up the idea as I am sure on StackOverFlow we have plenty of people who can help you guide in the right direction.

Please refer to this answer which I gave to this question

I would strongly recommend you watch the following videos on Youtube

  1. An interesting video by codeflood.
  2. Automated Testing with Sitecore V2

And prefer reading this blog post as well

  1. My preferred Coffee => Coder => Code by Alistair Deneys

Let us know if this was helpful.

Alright, I can gauge the blockage that you are facing. But have a read of this blog post by Kevin Obee. Sometimes while doing Unit Testing we loose the focus of being pragmatic and just follow the Unit Testing Principles.

I faced that and establishing the balance would be the key. In no way I am suggesting that you might have gone in this direction, but just suggesting that sometimes taking a step back, reflecting on what we ACTUALLY want to TEST and restarting helps a lot.

0
Mark Cassidy On

I suggest you start by looking over some of the posts in the blogosphere on the topic. In particular, Alistair Deneys has written quite a lot about this.

Mocking Sitecore: http://adeneys.wordpress.com/2012/04/13/mocking-sitecore/ Unit Testing in Sitecore: http://adeneys.wordpress.com/2010/11/20/unit-testing-in-sitecore-is-not-scary/

you'll find at least half a dozen more posts on the subject on his blog alone, and there's plenty of other resources available.

3
Marc On

There are quite some blogposts indeed as Mark Cassidy describes. In addition I'd like to point to chapter 8 of Professional Sitecore Development written by John West. He describes various approaches to unit testing (incl tests over http and using a web browser driver).

0
Wesley Lomax On

I found this post, Unit Testing with Sitecore, detailed and informative when looking at implementing Unit testing in Sitecore, it discusses techniques and approaches to make your code well structured and testable.