4

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.)

Community
  • 1
  • 1
dpwulp94
  • 163
  • 1
  • 8

4 Answers4

3

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.

Vojtěch Pešek
  • 1,070
  • 8
  • 25
Shriroop
  • 1,174
  • 2
  • 16
  • 28
  • The article of Unit Testing in Sitecore is not scary seems great. But it would be nice if there are some people on StackOverFlow who encountered the same problem, writen above. And (of course) how that was being solved. – dpwulp94 Nov 28 '13 at 11:28
  • Updated my answer, only saw your comment after the update. I do share the same thoughts and will investigate and put something together that might be helpful for everyone. Also please can you give a scenario (bit more code/one of your unit tests) in your question that might help people understand your frustrations/restrictions that you are up against in Sitecore Unit Testing. – Shriroop Nov 28 '13 at 11:37
2

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.

Mark Cassidy
  • 5,829
  • 1
  • 22
  • 33
0

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).

Marc
  • 1,798
  • 8
  • 15
  • We have that book at work and I have read chapter 8 as well, but that did not solve the problem I posted. – dpwulp94 Nov 28 '13 at 11:20
  • Did you ever tried the InMemory DataProvider approach described by Robin Hermanussen: http://hermanussen.eu/sitecore/wordpress/2012/06/sitecore-unit-testing-with-test-fixtures/. No need for the database then. – Marc Nov 28 '13 at 11:26
  • 1
    Just something to note, I believe Chapter 8 was pretty much done by Alistair Deneys, so most, if not all of it, you'll see on his Coffee => Coder => Code site, the one mentioned by someone else on here. Just saying if you don't want to double up your reading. – Sean Holmesby Nov 29 '13 at 05:08
0

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.

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34