Using The Builder Pattern to improve Testability and Readability

Sometimes setting things up can get a bit messy, especially when we want to test coupled code with a lot of dependencies. This is where the Builder Pattern comes in handy - it helps us create objects in an easier and cleaner way, especially when they are a bit complex to set up.…

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

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

Tutorial: How to setup a .NET Minimal API with integration testing using WebApplication Factory and NUnit

In this article I will share how you can setup an API using less than 20 lines of code using .NET Minimal API. Next we are going to setup an NUnit test project and using .NET WebApplicationFactory we will call the API endpoint and parse the resonse as an products array and compare the actual response to an expected json file embedded in our source code.…

Moq vs. NSubstitute vs. FakeItEasy

Today I though I would do some syntax comparison between a few of the biggest Mocking Framework in .NET: Moq, NSubstitute and FakeItEasy. Although these framework have slight functional differences they pretty much do the same thing but in different syntax and lingo.…

Loose vs. Strict mocking behaviour

I thought I would demonstrate the difference between Loose and Strict mocking behaviour when using the Moq Framework. By default when you create a new mock and don't specify a MockBehaviour it will be assigned MockBehaviour.Default, which equals to MockBehaviour.Loose.…

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

Using TestRunParameters in your NUnit tests using .runsettings

I've been getting a lot of traffic lately related to the google search phrase "nunit runsettings example" which at the moment leads to this blogpost I wrote on how to use Playwright with NUnit, which doesn't really cover how to set up .runsettings but rather how you can toggle headless mode in Playwright (totally different topic). So I thought I would share a little tutorial on how you can set up a new NUnit project and use .runsettings and TestRunParameters in your tests.…

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

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

Comparing different UI Testing frameworks (Selenium, Cypress and Microsoft Playwright)

So I decided that 2022 would be the year when I will start to implement more UI Testing in my projects. But, which framework should I choose?…

Using Microsoft Playwright and NUnit to automate search behaviour

I have been experimenting a lot with different UI testing frameworks such as Selenium, Cypress and Playwright in a public GitHub project and I’ve really come to fancy Microsoft.Playwright for .NET in combination with NUnit.…

Bread and Butter Testing

Ever heard the expression Bread and Butter Testing? Based on a quick Google Search I wouldn’t be too surprised if you haven’t and it could very much be a local expression* but I thought I would share what this expression means and how you may use it.…