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

## 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: [PowerShell](<https://devfeed.tech/topics/powershell.md>), [.NET](<https://devfeed.tech/topics/net.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Smoke Tests](<https://devfeed.tech/topics/smoke-tests.md>), [Playwright](<https://devfeed.tech/topics/playwright.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>)

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

### AI overview

This tutorial presents a PowerShell script that uses dotnet test and TRX result files to track failed tests, retry them, report the final result, and allow a configured percentage of failures. It demonstrates the script with NUnit, MSTest, and xUnit.

### 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: [Development](<https://devfeed.tech/topics/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>), [Testing](<https://devfeed.tech/topics/testing.md>), [unit tests](<https://devfeed.tech/topics/unit-tests.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>), [Testing](<https://devfeed.tech/topics/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>), [Testing](<https://devfeed.tech/topics/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...