Unit Testing with ChatGPT

/media/yinjlmhc/capture-unit2.png

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

Asserting Equal vs Same vs Equivalent

/media/nonjzvlr/equal-same-equivalent.png

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

Using The Builder Pattern to improve Testability and Readability

/media/45wkldxg/cover-21.png

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

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

Using TestRunParameters in your NUnit tests using .runsettings

/media/gd5jlv11/runsettings9.png

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

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

/media/fixj5hso/yrgo1.jpg

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

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

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

/media/1g4men0w/main.png

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

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

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

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

/media/ymnazl3f/cover-new.png

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

Characterization Testing Explained

/media/v5knyql1/characterization.png

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

Using the Fluent Builder Pattern to improve test readability and maintenance

/media/es2iqvns/cover-5.png

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

Could not find testhost

/media/wpkjoxmv/capture2.png

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

Getting started with Snapshot Testing using NUnit and Snapper

/media/blbj0m3p/cover-12.png

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 vs. Integration Testing

/media/zcbprouj/cover-17.png

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

Using Microsoft Playwright and NUnit to automate search behaviour

/media/t4edno4o/cover-13.png

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

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

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

Bread and Butter Testing

/media/accl0vsl/bread-and-butter.jpg

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