# NUnit

Published articles for NUnit.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS

DevFeed: [Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS](<https://devfeed.tech/articles/updating-to-net-8-updating-to-ihostbuilder-and-running-playwright-tests-within-nunit-headless-or-headed-on-any-os-77772.md>)

Original publisher: [Read original article](<https://feeds.hanselman.com/~/873234002/0/scotthanselman~Updating-to-NET-updating-to-IHostBuilder-and-running-Playwright-Tests-within-NUnit-headless-or-headed-on-any-OS>)

Author: Scott Hanselman

Published: 2024-03-07T01:12:13Z

Content type: tutorial

Language: en

Sources: [Scott Hanselman's Blog](<https://devfeed.tech/sources/scott-hanselman-s-blog.md>)

Topics: [Playwright](<https://devfeed.tech/topics/playwright.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [CI/CD](<https://devfeed.tech/topics/cicd.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [automation](<https://devfeed.tech/tags/automation.md>), [browser](<https://devfeed.tech/tags/browser.md>), [ci-cd](<https://devfeed.tech/tags/ci-cd.md>), [dotnetcore](<https://devfeed.tech/tags/dotnetcore.md>), [net](<https://devfeed.tech/tags/net.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [playwright](<https://devfeed.tech/tags/playwright.md>)

### AI overview

The article describes upgrading a .NET site to .NET 8 and adapting its host setup so NUnit tests can start the web application in TestHost. It demonstrates running Playwright browser integration tests across operating systems, in containers, and in CI, and explains a content-root workaround involving the MvcTesting package.

### Source excerpt

I've been doing not just Unit Testing for my sites but full on Integration Testing and Browser Automation Testing as early as 2007 with Selenium. Lately, however, I've been using the faster and generally more compatible Playwright. It has one API and can test on Windows, Linux, Mac, locally, in a container (headless), in my CI/CD pipeline, on Azure DevOps, or in GitHub Actions. For me, it's that last moment of truth to make sure that the site runs completely from end to end. I can write those Playwright tests in something like TypeScript, and I could launch them with node, but I like running end unit tests and using that test runner and test harness as my jumping off point for my .NET applications. I'm used to right clicking and "run unit tests" or even better, right click and "debug unit tests" in Visual Studio or VS Code. This gets me the benefit of all of the assertions of a full unit testing framework, and all the benefits of using something like Playwright to automate my browser. In 2018 I was using WebApplicationFactory and some tricky hacks to basically spin up ASP.NET within .NET (at the time) Core 2.1 within the unit tests and then launching Selenium. This was kind of janky and would require to manually start a separate process and manage its life cycle. However, I kept on with this hack for a number of years basically trying to get the Kestrel Web Server to spin up inside of my unit tests. I've recently upgraded my main site and podcast site to .NET 8. Keep in mind that I've been moving my websites forward from early early versions of .NET to the most recent versions. The blog is happily running on Linux in a container on .NET 8, but its original code started in 2002 on .NET 1.1. Now that I'm on .NET 8, I scandalously discovered (as my unit tests stopped working) that the rest of the world had moved from IWebHostBuilder to IHostBuilder five version of .NET ago. Gulp. Say what you will, but the backward compatibility is impressive. As such my code for Progr

## Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS

DevFeed: [Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS](<https://devfeed.tech/articles/updating-to-net-8-updating-to-ihostbuilder-and-running-playwright-tests-within-nunit-headless-or-headed-on-any-os-21858.md>)

Original publisher: [Read original article](<https://www.hanselman.com/blog/updating-to-net-8-updating-to-ihostbuilder-and-running-playwright-tests-within-nunit-headless-or-headed-on-any-os>)

Author: Scott Hanselman

Published: 2024-03-07T01:12:13Z

Content type: article

Language: en

Sources: [Scott Hanselman](<https://devfeed.tech/sources/scott-hanselman.md>)

Topics: [Playwright](<https://devfeed.tech/topics/playwright.md>), [Browser Automation](<https://devfeed.tech/topics/browser-automation.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [NUnit](<https://devfeed.tech/topics/nunit.md>), [Headless Browser](<https://devfeed.tech/topics/headless-browser.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>), [CI/CD](<https://devfeed.tech/topics/cicd.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [azure-devops](<https://devfeed.tech/tags/azure-devops.md>), [browser](<https://devfeed.tech/tags/browser.md>), [browser-automation](<https://devfeed.tech/tags/browser-automation.md>), [ci-cd-pipeline](<https://devfeed.tech/tags/ci-cd-pipeline.md>), [container](<https://devfeed.tech/tags/container.md>), [core](<https://devfeed.tech/tags/core.md>), [dotnetcore](<https://devfeed.tech/tags/dotnetcore.md>), [github-actions](<https://devfeed.tech/tags/github-actions.md>), [headless](<https://devfeed.tech/tags/headless.md>), [linux](<https://devfeed.tech/tags/linux.md>), [net](<https://devfeed.tech/tags/net.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [os](<https://devfeed.tech/tags/os.md>), [playwright](<https://devfeed.tech/tags/playwright.md>), [tests](<https://devfeed.tech/tags/tests.md>), [updating](<https://devfeed.tech/tags/updating.md>)

### AI overview

The author describes moving ASP.NET apps to .NET 8 and updating Program.cs from IWebHostBuilder to IHostBuilder after existing NUnit tests stopped starting Kestrel. They prefer running Playwright browser automation through .NET's test harness, which supports unit test assertions and Visual Studio or VS Code test and debug workflows. The author says Playwright works across Windows, Linux, and Mac, locally or in containers and CI systems, and contrasts this with an earlier WebApplicationFactory and Selenium setup that required manually managing a separate process. The excerpt ends before showing the revised server startup or complete NUnit example.

### Source excerpt

I've been doing not just Unit Testing for my sites but full on Integration Testing and Browser Automation Testing as early as 2007 with Selenium. Lately, however, I've been using the faster and generally more compatible Playwright. It has one API and can test on Windows, Linux, Mac, locally, in a container (headless), in my CI/CD pipeline, on Azure DevOps, or in GitHub Actions. For me, it's that last moment of truth to make sure that the site runs completely from end to end. I can write those Playwright tests in something like TypeScript, and I could launch them with node, but I like running end unit tests and using that test runner and test harness as my jumping off point for my .NET applications. I'm used to right clicking and "run unit tests" or even better, right click and "debug unit tests" in Visual Studio or VS Code. This gets me the benefit of all of the assertions of a full unit testing framework, and all the benefits of using something like Playwright to automate my browser. In 2018 I was using WebApplicationFactory and some tricky hacks to basically spin up ASP.NET within .NET (at the time) Core 2.1 within the unit tests and then launching Selenium. This was kind of janky and would require to manually start a separate process and manage its life cycle. However, I kept on with this hack for a number of years basically trying to get the Kestrel Web Server to spin up inside of my unit tests. I've recently upgraded my main site and podcast site to .NET 8. Keep in mind that I've been moving my websites forward from early early versions of .NET to the most recent versions. The blog is happily running on Linux in a container on .NET 8, but its original code started in 2002 on .NET 1.1. Now that I'm on .NET 8, I scandalously discovered (as my unit tests stopped working) that the rest of the world had moved from IWebHostBuilder to IHostBuilder five version of .NET ago. Gulp. Say what you will, but the backward compatibility is impressive. As such my code for Progr

## Retry flaky tests with dotnet test and PowerShell

DevFeed: [Retry flaky tests with dotnet test and PowerShell](<https://devfeed.tech/articles/retry-flaky-tests-with-dotnet-test-and-powershell-20782.md>)

Original publisher: [Read original article](<https://conductofcode.io/post/retry-flaky-tests-with-dotnet-test-and-powershell/>)

Author: {"twitter"=\>"hlaueriksson"}

Published: 2023-03-26T19:00:00Z

Content type: tutorial

Language: en

Sources: [Henrik Lau Eriksson](<https://devfeed.tech/sources/henrik-lau-eriksson.md>)

Topics: [Test automation](<https://devfeed.tech/topics/test-automation.md>), [PowerShell](<https://devfeed.tech/topics/powershell.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>), [mstest](<https://devfeed.tech/topics/mstest.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [cli](<https://devfeed.tech/tags/cli.md>), [dotnet](<https://devfeed.tech/tags/dotnet.md>), [flaky](<https://devfeed.tech/tags/flaky.md>), [flaky-tests](<https://devfeed.tech/tags/flaky-tests.md>), [mstest](<https://devfeed.tech/tags/mstest.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [powershell](<https://devfeed.tech/tags/powershell.md>), [retries](<https://devfeed.tech/tags/retries.md>), [retry](<https://devfeed.tech/tags/retry.md>), [script](<https://devfeed.tech/tags/script.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [xunit](<https://devfeed.tech/tags/xunit.md>)

### AI overview

The PowerShell `test.ps1` script runs `dotnet test`, reads failed tests from the TRX result file, and reruns those tests up to a configured retry count. It can pass the current retry iteration to the test framework, filter selected tests, and treat a configured percentage of passed tests as success. It returns exit code 0 when tests pass or meet that threshold; otherwise, it returns the number of failed tests. The excerpt says the author showcases NUnit, MSTest, and xUnit integrations, but cuts off during the xUnit details. Parameter defaults, ranges, and sample commands are omitted.

### Source excerpt

Introducing test.ps1, a script for running flaky tests - Keeps track of failing tests and retries them - Notifies the test framework of the current retry iteration - Makes it possible to accept a certain percentage of failing tests - Outputs the test result in a coherent way

## REPL Driven Development

DevFeed: [REPL Driven Development](<https://devfeed.tech/articles/repl-driven-development-31904.md>)

Original publisher: [Read original article](<http://blog.jayfields.com/2014/01/repl-driven-development.html>)

Author: Jay (noreply@blogger.com)

Published: 2014-01-27T17:53:00Z

Content type: opinion

Language: en

Sources: [Jay Fields](<https://devfeed.tech/sources/jay-fields.md>)

Topics: [software-development](<https://devfeed.tech/topics/software-development.md>), [Code](<https://devfeed.tech/topics/code.md>), [Software](<https://devfeed.tech/topics/software.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [application](<https://devfeed.tech/tags/application.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [clojure](<https://devfeed.tech/tags/clojure.md>), [code](<https://devfeed.tech/tags/code.md>), [development](<https://devfeed.tech/tags/development.md>), [emacs](<https://devfeed.tech/tags/emacs.md>), [evaluation](<https://devfeed.tech/tags/evaluation.md>), [expression](<https://devfeed.tech/tags/expression.md>), [java](<https://devfeed.tech/tags/java.md>), [junit](<https://devfeed.tech/tags/junit.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [productivity](<https://devfeed.tech/tags/productivity.md>), [repl](<https://devfeed.tech/tags/repl.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [running](<https://devfeed.tech/tags/running.md>), [software](<https://devfeed.tech/tags/software.md>), [verification](<https://devfeed.tech/tags/verification.md>), [writing](<https://devfeed.tech/tags/writing.md>)

### AI overview

The article explains REPL Driven Development (RDD), a workflow in which developers craft s-expressions, evaluate them immediately in a REPL, inspect the results or apply changes to a running application, and repeat until the problem is solved. The author argues that avoiding application restarts, separate verification tools, and leaving the source enables faster feedback while writing production code.

### Source excerpt

When I describe my current workflow I use the TLA RDD, which is short for REPL Driven Development. I've been using REPL Driven Development for all of my production work for awhile now, and I find it to be the most effective workflow I've ever used. RDD differs greatly from any workflow I've used in the past, and (despite my belief that it's superior) I've often had trouble concisely describing what makes the workflow so productive. This entry is an attempt to describe what I consider RDD to be, and to demonstrate why I find it the most effective way to work. RDD Cycle First, I'd like to address the TLA RDD. I use the term RDD because I'm relying on the REPL to drive my development. More specifically, when I'm developing, I create an s-expression that I believe will solve my problem at hand. Once I'm satisfied with my s-expression, I send that s-expression to the REPL for immediate evaluation. The result of sending an s-expression can either be a value that I manually inspect, or it can be a change to a running application. Either way, I'll look at the result, determine if the problem is solved, and repeat the process of crafting an s-expression, sending it to the REPL, and evaluating the result. If that isn't clear, hopefully the video below demonstrates what I'm talking about. If you're unfamiliar with RDD, the previous video might leave you wondering: What's so impressive about RDD? To answer that question, I think it's worth making explicit what the video is: an example of a running application that needs to change, a change taking place, and verification that the application runs as desired. The video demonstrates change and verification; what makes RDD so effective to me is what's missing: (a) restarting the application, (b) running something other than the application to verify behavior, and (c) moving out of the source to execute arbitrary code. Eliminating those 3 steps allows me to focus on what's important, writing and running code that will be executed in

## BDD ideas for structuring tests

DevFeed: [BDD ideas for structuring tests](<https://devfeed.tech/articles/bdd-ideas-for-structuring-tests-33387.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2012/01/02/bdd-ideas-for-structuring-tests>)

Published: 2012-01-02T00:00:00Z

Content type: opinion

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Behavior-driven development](<https://devfeed.tech/topics/bdd.md>), [C#](<https://devfeed.tech/topics/csharp.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [NUnit](<https://devfeed.tech/topics/nunit.md>), [Visual Studio](<https://devfeed.tech/topics/visual-studio.md>)

Tags: [bdd](<https://devfeed.tech/tags/bdd.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>), [visual-studio](<https://devfeed.tech/tags/visual-studio.md>)

### AI overview

The author discusses ways to structure behavior-driven development tests in C#. The article considers nested classes that organize tests by method, notes their compatibility with Visual Studio navigation, and compares that approach with namespace- and method-based setup practices.

### Source excerpt

Lately I've been thinking a lot about the best way to do BDD in C#. So when I saw Phil Haack's post about structuring unit tests, I think I had a joyful thought. Earlier I had been thinking in terms of using my Behavioral NUnit experimental project to hash out Haack's structuring idea with better BDD integration.In short, his idea is to use nested classes. There is the normal one-to-one class-to-test-class mapping, but each method under test gets it's own inner class. To use his example:In this example the Titleify and Knightify methods (imo two terrible uses of the -ify suffix) have corresponding test classes dedicating to testing only one method. Each method in the class (or Fact, in the case of xUnit. I actually haven't used xUnit but it seems to encourage a somewhat BDD readability) test one aspect of the method, much like the it method is used in rspec.I generally like Haack's test structure. For example, he points out how it plays nicely with Visual Studio's natural class/method navigation which makes the tests even more navigable. The only issue I have with it is that I dislike having 1000+ SLOC classes - tests or regular. If I were to adopt this method, I would probably break each of those inner classes into separate files (and use partial classes to break up the top class).My practice for a long time was to have one whole namespace per class under test. Consider my tests for objectflow. I actually picked up this practice from Garfield Moore, objectflow's original developer. Each class (or significant concept) has a namespace (e.g. objectflow.stateful.tests.unit.PossibleTransitions or PossibleTransitionTests). Each class in that namespace is names according to essentially what the Setup does. Some examples: WhenGivenOnlyBranches, WhenGivenOnlyYields, etc.I like the way these tests read. It's very easy to find a particular test or to read up on how a particular method is supposed to operate. But in practice this has led to very deep hierarchies, often with si

## Behavior Driven Development in C#

DevFeed: [Behavior Driven Development in C#](<https://devfeed.tech/articles/behavior-driven-development-in-c-33385.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/12/28/behavior-driven-development-in-c>)

Published: 2011-12-28T00:00:00Z

Content type: opinion

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Behavior-driven development](<https://devfeed.tech/topics/bdd.md>), [C#](<https://devfeed.tech/topics/csharp.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [NUnit](<https://devfeed.tech/topics/nunit.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>)

Tags: [bdd](<https://devfeed.tech/tags/bdd.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [rspec](<https://devfeed.tech/tags/rspec.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-test](<https://devfeed.tech/tags/unit-test.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>)

### AI overview

The author explains why behavior-driven development became more manageable than conventional unit-test naming for complex code. They compare Ruby RSpec and .NET BDD approaches, and describe a simple BDD layer over NUnit to preserve its tooling and lower the barrier to contribution.

### Source excerpt

I've been a fan of Test Driven Development since I worked in an XP shop. But every time the work starts getting bigger and more complex I always struggle to not get lost in the magnitudes of tests. I remember many early-on conversations with my elders about unit test naming conventions. The [method]_[input]_[output] convention starts to break down badly when your inputs become things like mocks, or if there ends up being more than 1 or 2 inputs; same with outputs.When a coworker introduced me to BDD earlier this year, it really clicked and flowed naturally. The idea of writing tests so they read like sentences out of a book or spec seems like the answer to all my questions. The ruby rspec is beautiful:The organization of the tests forces you to focus on the expectations of your test and highlight descriptive assertions. This is especially useful for complicated setups with lots of mocks, etc. I put as much of my setup code in one of those before :each blocks, so that way the assertions are limited to simple inputs and one or two observations about the outputs.There's been a number of people in the .NET community that have attempted BDD but [imo] failed to grasp the simplicity. NBehave is a complete overhaul of unit testing that uses attributes like xUnit. As a result, NBehave doesn't really look at all like rspec - which really isn't a bad thing, necessarily. However, the thing I like about rspec is it's ability to describe things of arbitrary depth, which is handy when testing complex code:This spec is able to describe possible modes that the object under test can be in (complex inputs). This is made possible by rspec's arbitrary nesting depth. This is definitely a language feature that is much harder to implement in C#.My current approach to BDD in C# usually looks likeI think this is the simplest BDD layer I can slap on top of NUnit. And simple is important to me because (a) I do a lot of open source projects and I want to keep the barrier to entry for contributi

## Scripting with rake

DevFeed: [Scripting with rake](<https://devfeed.tech/articles/scripting-with-rake-33367.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/04/20/scripting-with-rake>)

Published: 2011-04-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [make](<https://devfeed.tech/topics/make.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [NUnit](<https://devfeed.tech/topics/nunit.md>), [Visual Studio](<https://devfeed.tech/topics/visual-studio.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [cli](<https://devfeed.tech/tags/cli.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [make](<https://devfeed.tech/tags/make.md>), [net](<https://devfeed.tech/tags/net.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [rake](<https://devfeed.tech/tags/rake.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [visual-studio](<https://devfeed.tech/tags/visual-studio.md>)

### AI overview

This article explains how to use Rake as a Ruby-based build and scripting tool. It compares Rake with make, Ant, and NAnt, discusses dependency and file tasks, and describes using Albacore for .NET builds and related development automation.

### Source excerpt

Rake is a great twist on traditional make (honestly, I never really liked Ant or NAnt). On the surface it looks more like make than Ant or Nant, but you can leverage the full syntax and standard library of Ruby (and there's no weird rules about tabs). As a .NET developer, albacore augments rake nicely with tasks for MSBuild (building Visual Studio projects and solutions), NUnit, ASP.NET precompiler, modifying your AssemblyInfo.cs (like for bumping the version number), and many more.Since rake is just ruby code, you can do just about anything, but most file manipulation routines are even easier to write in rake, because most everything is already imported and ready to use. Unlike make, Ant, and Nant, you don't have to start a separate project just to develop tools to use in a rakefile, just write a ruby function!Building dependencies firstA lot of people who aren't already familiar with build languages make some common mistakes. Among them, not using dependencies correctly. For instance, given a website solution that references frameworkmsbuild :framework do |msb| msb.solution = 'framework/src/framework.sln'endmsbuild :website do |msb| msb.solution = 'src/website.sln'endtask :default => [:framework, :website]The default task is the task that's executed when you just type rake at the CLI. The reason this is terrible is that it's procedural and inflexible. Now, if I do rake website the build fails because framework hasn't been built yet. Instead, each task should specify what other tasks it directly relies on. This script should change to:msbuild :framework do |msb| msb.solution = 'framework/src/framework.sln'endmsbuild :website => :framework do |msb| msb.solution = 'src/website.sln'endtask :default => :websiteThis way both rake and rake website work the same. This leverages rakes dependency framework that is at the core of all build languages.Using file tasksThe other point that people often forget is that build languages are oriented around files. Make tasks were ori

## NUnit Extension Methods

DevFeed: [NUnit Extension Methods](<https://devfeed.tech/articles/nunit-extension-methods-33359.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/02/26/nunit-extension-methods>)

Published: 2011-02-26T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [NUnit](<https://devfeed.tech/topics/nunit.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Unit testing](<https://devfeed.tech/topics/unit-testing.md>), [Code](<https://devfeed.tech/topics/code.md>), [Framework](<https://devfeed.tech/topics/framework.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [framework](<https://devfeed.tech/tags/framework.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [object](<https://devfeed.tech/tags/object.md>), [static](<https://devfeed.tech/tags/static.md>), [testing](<https://devfeed.tech/tags/testing.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>)

### AI overview

This article presents NUnit extension methods that wrap common assertions such as Assert.AreEqual, Assert.IsNull, and Assert.IsNotNull. The methods provide a more readable style, including calls such as actual.ShouldBe(expected) and actual.ShouldBeNull().

### Source excerpt

I've always used NUnit for testing code so it's naturally the framework I'm most familiar with (I haven't used anything else). I learned unit testing using the classic Assert.AreEqual(expected, actual) methods. Although, I was finding my tests slightly confusing to read - I sometimes can't remember which comes first, expected or actual.More recently I've been getting into v2.5 including the new asserts - Assert.That(actual, Is.EqualTo(expected)). I think this makes a lot of sense and I often find myself using Assert.That most of the time just because it makes sense.Recently, a coworker created a few extension methods that I'm finding quite handy:public static void ShouldBe(this object @this, object expected) { Assert.AreEqual((dynamic)expected, (dynamic)@this);}public static void ShouldNotBe(this object @this, object expected) { Assert.AreNotEqual((dynamic)expected, (dynamic)@this);}public static void ShouldBeNull(this object @this) { Assert.IsNull(@this);}public static void ShouldNotBeNull(this object @this) { Assert.IsNotNull(@this);}I've completely fallen in love with how this reads: actual.ShouldBe(expected). It also makes me giggle to do actual.ShouldBeNull() (Don't you love extension methods?). This makes unit testing so easy...