codeflood logo

Posts tagged in Testing

Unit Testing Sitecore Components Part 5: Recap and Resources

This is the final post in my "Unit Testing Sitecore Components" series. In this series I've taken a seemingly simplistic Sitecore component and refactored it by applying several principals to make the code more reusable and testable. In this final post of the series I'll recap the principals and provide a few resources to help explain them further.

Unit Testing Sitecore Components Part 4: Mocking Items and Fields

In the previous posts of this series, I've refactored an existing Sitecore component to make it's logic more reusable and prepare the component and the logic it includes for unit testing. In this post I'll be writing the unit tests for the refactored EntryTaxonomy class, showing how to mock items and field values.

Unit Testing Sitecore Components Part 3: Avoid Static Members

In the posts of this series so far, I've refactored a sample view rendering to make the rendering itself unit testable. In doing do I've extracted the business logic to a separate class which still needs some work before it can be properly tested. In this post, I'll be covering 2 more principals to help with making Sitecore components more testable and reusable.

Unit Testing Sitecore Components Part 2: Encapsulate Logic

In the previous post of this series I detailed 2 principals which can help with making Sitecore components more testable and reusable. These were "keeping the business logic out of the view" and "keeping the Item class out of the model". In this post I'll detail several more principals to continue improving the code.

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.

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.

Testable Code

Ahhh, automated testing. It's what gives you that warm fuzzy feeling that your code is all working as you intended. A validation that you're free from errors and a safety net for future modifications. OK, perhaps not necessarily free from errors, but you at least know the cases you've got covered are correct, and they're easy to run at any time to validate those cases are still working as...

What to Test?

Recently I was having a discussion with someone around how to test certain scenarios in Sitecore. The scenario in question involved testing a sublayout on a page to ensure it was working properly, and the developer was thinking of using something like Selenium to do this. This raised a flag with me. Although there are scenarios in which an automated web tester is the correct approach for this...

Mocking Sitecore

Whenever I talk about unit testing and Sitecore, someone inevitably will ask about the practise of mocking. Mocking involves creating a simple object to replace a dependency in your unit tests so your test code doesn’t have to invoke that dependency. The issue I’ve had with mocking is that you have to deeply understand the object you’re mocking or your mocks won’t be a reflection of the dependency...

Automated Testing in Sitecore Without an HttpContext

This year was the first year that Sitecore’s Dreamcore conference was held in Australia. And I for one jumped at the opportunity to speak at it. One topic that quite interests me is unit testing, and if you’ve read my posts over the years you’d see I have come up with a variety of techniques for getting unit testing (or rather, integration testing) working for Sitecore projects. So what better...

Presenting to the Sitecore Users Virtual Group

This Thursday (well, it will be Thursday for me, Wednesday if you’re on the other side of the date line) I’ll be presenting to the Sitecore Users Virtual Group on testing strategies for Sitecore. This is the same talk I gave at Dreamcore this year, so if you missed out, here’s another opportunity to see me talk about some testing techniques. Details can be found here:...

Dreamcore AU 2011

It was my great pleasure to present at Sitecore’s Dreamcore event in Sydney, Australia this week. This was the first time the conference was held in Australia and it was fantastic with lots of great speakers and interesting people. My session was titled “Testing Strategies for Sitecore” and was run in the developer stream, so it focused on automated/unit testing. As promised for everyone who...

Unit Test Test Data

One of the most valuable lessons I learnt whilst doing unit testing with Sitecore projects was to ensure my tests were robust and repeatable. I went through a lot of pain in my earlier projects with brittle tests that as soon as one test failed, all the others would start failing. All this instability was to do with the test data I was using. I had a small amount of test content that I assumed was...

More Unit Testing in Sitecore Videos

I've finally found enough free time to record the continuation of my first unit testing in Sitecore video which showed how to add a test project to your solution which used the codeflood custom NUnit test runner. The next video was a little larger than I expected and I had to split it out into 2 separate videos. The first shows how to prepare your unit test fixture for writing tests by creating...

Unit Testing in Sitecore is Not Scary

I was chatting to another Sitecore developer the other day about unit testing in Sitecore. The impression I got from the developer was that although they knew unit testing could be done, they felt it was quite cumbersome and difficult. Possibly the length of my previous series on unit testing in Sitecore didn’t help the cause either. So I’d like to show you just how easy unit testing in Sitecore...

New Technique for Unit Testing Renderings in Sitecore

Unit testing in Sitecore always seems to be a hot topic amongst the Sitecore community, especially the new comers to the Sitecore game. And rightly so. Working out how you can effectively unit test your Sitecore code can be very confusing when you’re still trying to come to grips with a new system and it’s way of doing things. And it’s not immediately apparent how you can do such testing. I think...

Automated Testing and Sitecore - Part 8

Well. When I started writing this multi-part series on automated testing and Sitecore I never intended for it to flow over into 8 parts. But I think what I've covered in this series are the fundamental pieces any developer requires to be able to affectively automate their tests for Sitecore code. So, now that we're at the end of the series, I'll leave you with some tips. Don't get hung up on...

Automated Testing and Sitecore - Part 7

In the previous part of this series we covered testing the static output and behaviors of Sitecore presentation components such as rendering, layout and sublayout. But what about testing the dynamic behaviors of a component, such as "what happens when I push the button?", or "did my javascript make the ajax call to grab the content from the CMS?". In this part of the series...

Page: 1 2