Asserting Equal vs Same vs Equivalent

In this article, I'm going to demonstrate three very common but possibly confusing assertion differences in the world of C# testing: Assert.AreEqual, Assert.AreSame and Should().BeEquivalentTo.…

Unit Testing with ChatGPT

Don't like writing unit tests or simply don't have the time for it? Good news – now you don't have to! As a newbord AI enthusiast with a long-time obsession with unit testing, I couldn't resist the urge to try and combine these two topics. Check out my latest blog post "Unit Testing with ChatGPT," to discover how you can use ChatGPT to generate test cases and code for you.…

Unit vs. Integration Testing

By understanding the essential differences between unit and integration testing, we as developers can make better decisions about when and how to use each type of testing to ensure the quality and reliability of our software.…

Getting started with Snapshot Testing using NUnit and Snapper

Snapshot testing is a valuable technique for testing software applications. Using this technique we can capture the state of an application at a specific point in time and compare it to a previously recorded state, known as a snapshot.…

Unit Testing private methods in C#

Should private methods in C# be Unit Tested? Generally you don’t write unit tests for private methods since they are not accessed from outside the implementation class (private methods are considered implementation detail).…

Could not find testhost

A while back I wrote an article on this subject where you have NUnit tests not running in Visual Studio and how to fix it. In this blogpost I will share the same soluition expect with xUnit since it involves some other packages and error messages it might not be clear that it is a related issue.…

Using the Fluent Builder Pattern to improve test readability and maintenance

Using this pattern we create an test object builder that will centralize redundant (and sometimes complex) logic that we don’t want to have in each and every one of our tests. This will make our tests slimmer and more focused on what is actually important for the state of which is being tested.…

Characterization Testing Explained

This is a technique I’ve been using for years but it wasn’t until recently that I realized that it actually has a specific name. Using characterization testing we lock the current behavior in one of several tests before we go refactor code (usually untested legacy) to be comfortable that our improvement didn’t break any existing behavior.…

Comparing mocking frameworks: How to handle optional parameter with NSubstituite, Moq and FakeItEasy

Depending on which mocking framework you are using you might have to handle optional parameters differently and in this short article I will compare and demonstrate the differences in the three major mocking frameworks NSubstitute, Moq and FakeItEasy.…

NUnit tests is not found or do not run in Visual Studio's Test Explorer

Having problems with your NUnit tests not running as expected in Visual Studio's Test Explorer? Even wiered, the tests might work for other members of your team but for some reason not for you?…

5th year teaching .NET Testing at local university college YRGO

Today I had the privilege of lecturing for the 5th year at Yrgo University college on the subject of .NET Testing. As always, the goal has been to give students a positive impression of testing early in their career and that writing tests is not something you "should" or "must" do but something you WANT to do because it is a fun and challenging part of being a developer.…

Unit Testing in Umbraco 9-10.x

The other day I got a friendly heads up from Umbraco Documentation Team member Sofie Toft that the official Umbraco Unit Testing documentation had not yet been verified against the latest major version of Umbraco (v10).…

CMS and Testing presentation at a local "mini-meetup"

Yesterday me and three of my coworkers arranged a "mini-meetup" for a local university here in Gothenburg called Medieinstitutet. We each did presentations that represented our skill: Frontend, Backend (me) and QA.…

Integration Testing an Umbraco API using .NET Web Application Factory

Lately I've been experimenting with the new WebApplicationFactory in .NET 6.0 together with custom Umbraco API controllers to verify that each API endpoint is up and running and that they return the expected output.…

Testing an Umbraco Dictionary value using ICultureDictionary and UmbracoHelper

This week I finally found time to work on converting the Umbraco Unit Testing documentation from v8 to v9. The v9 version had some basic examples that I created a while back, but I want to bring all the examples from the v8 version in to the lastest version.…

Trust your tests!

Tests are meant to replace our browser clicking and instead give us instant and reliable feedback if our code is working or not. The browser is just a presentation layer. Trust your tests!…

The Umbraco 9 Unit Testing Documentation

By the end of last week I got my #hacktoberfest pull request to Umbraco merged and this morning it was finally live: The Umbraco 9 Unit Testing Documentation!…

Unit Testing with AutoFixture to generate TestCase data

When writing unit tests I often find myself having to come up with these kind of random test case data. But I recently discovered a package called AutoFixture which not only replaces all of the test case data in my tests but also saves me the trouble of having to come up with these random values myself.…

Teaching Unit Testing at a local University College

Today I had the pleasure of lecturing .NET Unit Testing at YRGO, a local University College in Gothenburg. This was actually the fourth year lecturing at YRGO and it’s something I really enjoy doing next to my “regular” work assignments. This session was based a lot on my session from my CodeGarden talk earlier this year.…

Mocking the UmbracoHelper in Umbraco 9

I’ve always had somewhat of a love-hate relationship with the UmbracoHelper, mostly because until recently it has been a lot of work mocking this little helper. Until now!…

Mocking Property Values in Umbraco 9 (and Umbraco 8)

So I just got back from my summer vacation and I thought I would kickstart this blogging thing with a short and straight-forward blogpost that's easy to digest for anyone (like me) coming back from a long break from coding.…

Testing the untestable with the Adapter Design Pattern

During my session at last weeks Codegarden on ‘Getting started with Unit Testing in Umbraco’ I got a really good question in the Q&A afterwards, and I thought I would share the question and elaborate on my answer: -“What tips do you have for mocking services that are overly complex or have lots of dependencies that can't be null?”…

I’m a speaker at Umbraco Codegarden 2021

This week I got some exciting news: My session on “Getting started with Unit Testing in Umbraco” has been accepted for Umbraco Codegarden 2021!…

Testing Umbraco Composers

Something I’ve been wanting to write a test for but haven't come around to yet is the Umbraco Composer that was introduced in version 8. This could look something like this.…

Unit Testing an Url Segment Provider in Umbraco

Using an IUrlSegmentProvider you can modify the url segment that Umbraco generates for any piece of content based on whatever conditions you like. This week I created a test example for this ProductPageUrlSegmentProvider and updated the GitHub project and I'll be submitting a PR to the Unit Testing documentation.…

Umbraco Leeds Meetup Summary

So yesterday was finally the day for my presentation at the Umbraco Leeds Meetup about “Getting started with Unit Testing in Umbraco”.…

Unit Testing Regular Expressions

Not only are unit tests great for securing the behaviour of your code but they also serve as form of living documentation and one area where I find this especially true is when covering regular expressions with your unit tests.…

NUnit vs. xUnit

The endless battle between the two testing frameworks NUnit and xUnit is a hot potato and in this blog post I intend to give my two cents on this topic.…

Getting started with Unit Testing #2: Don't get stuck!

A mistake you might do as a beginner tester (I probably did it myself in the beginning) is that you start of hopefully to a great start, testing is going great and you think you’ve got the hang of it…

Getting started with Unit Testing #1: Start fresh!

A lot of developers who embark on the Unit Testing journey will go: -"Okay, I'll write a test in my current project just to see how it feels!". This is almost always a bad idea and chances are you’re going to get stuck and give up. And here's why..…

Five tricks to speed up your Unit Testing today

One of the main reasons I hear for not writing tests is -"We don’t have the time!" and that it feels like it would take longer time to write code with test than without. But there are a few tricks you can apply to speed up your Unit Testing today.…

I’ll be speaking at the Umbraco Leeds Meetup

I’ll be speaking about Unit Testing and Umbraco at the Umbraco Leeds Meetup on the 6th of April. In this session I’ll be covering the basics of Unit Testing, how to get started and talk a little about my work with the official documentation and GitHub project on Unit Testing in Umbraco.…

Using Umbraco Health Checks as Integration Tests, Revisited!

Almost every one of our projects moves towards a microservice architecture and our applications are rarely these huge web apps anymore, but instead they are a bunch of applications working together in a cluster of apps.…

API Testing using Test Driven Development (TDD)

This week I’ve been working on an integration to an external provider used for newsletters subscriptions and I’ve realised that if there’s one area where TDD is a match made in heaven it’s when you're doing API Testing.…

Umbraco Unit Testing Updated: February 1, 2021

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

Starting to Unit Test: Not as Hard as You Think

I thought I would share a recommendation for a really great book that I think anyone who is new to Unit Testing should read: Starting to Unit Test: Not as Hard as You Think by Erik Deitrich. I read this book many years ago but I remember it to this day because it was an eye opener to what Unit Testing essentially is.…

Parallelism: NUnit vs. xUnit

Running your tests in parallel can significantly improve the speed of your test runs, but it could give you occasional problems especially if you're working on static implementations. Also turns out that depending on which testing framework you're using parallelism might be handled differently.…

Getting started with Unit Testing in Umbraco just got a whole lot easier!

Around two years ago Umbraco version 8 was released and I was scanning the internet trying to find some documentation on how to do Unit Testing in version 8, without any luck. No examples or tutorials had yet to be made for this and the official documentation did not have a section on Unit Testing. So I thought: How hard can it be?…

How to test internal classes

When you're writing unit tests you may sometimes find yourself in a situation where you need to be able to access an internal class from within another project such as your *.Tests project.…