Umbraco Unit Testing Updated: February 1, 2021

As I mentioned in a previous post from January 21th I started a little side-gig which is a GitHub repository gathering all the Unit Tests from the official Umbraco Documentation section in a ready-made solution that anyone can just clone, run locally and start experimenting with Unit Testing in Umbraco. The goal is to remove the hardest part of getting started with Unit Testing, which is usually the "Getting started" part.

I aim to keep this project in-sync with the official Documentation so that if the Documentation is updated then I will update the GitHub project but also the other way around: if the GitHub project get updated with additional tests I will make sure to update the Documentation. Which is what I did yesterday.

The hardest part of getting started with Unit Testing is usually the "Getting started" part. Not anymoe!

More test examples!

I had a little sparetime yesterday so I extended the UmbracoUnitTesting project with three additional tests examples and so I've also submitted these tests as a pull request to the Umbraco Documentation. 

Mocking PublishedContentQuery ContentAtRoot():

Mocking IPublishedContent .Url:

Yes, I am awear that .Url is deprecated and should be replaced with the .Url() extension, which seems to be untestable. See conversation on Twitter.

Testing JSON output from an UmbracoApiController:

Nothing groundbreaking

There's nothing groundbreaking with these tests, if you´re an experienced tester they might seem trivial for you. But remember that it's the little things that experienced developers take for granted that "everybody knows" that doesn't get documented or blogged about and it's usually these things beginner developers tend to get stuck on.

It's the things experienced developers take for granted that beginner developers tend to get stuck on.

I'm just happy if it can help someone. If it helps one person it was worth the trouble.

Take care of each other.
Cheers friends! ❤️