Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

shouldly

> 测试质量
Open source

Should testing for .NET—the way assertions should be!

3.4K stars0 likes2 views
WebsiteGitHub

About

Should testing for .NET—the way assertions should be!


Shouldly is an assertion framework which focuses on giving great error messages when the assertion fails while being simple and terse.

This is the old Assert way:

cs
Assert.That(contestant.Points, Is.EqualTo(1337));

For your troubles, you get this message, when it fails:

Expected 1337 but was 0

How it Should be:

cs
contestant.Points.ShouldBe(1337);

Which is just syntax, so far, but check out the message when it fails:

contestant.Points should be 1337 but was 0

It might be easy to underestimate how useful this is. Another example, side by side:

cs
Assert.That(map.IndexOfValue("boo"), Is.EqualTo(2));    // -> Expected 2 but was -1
map.IndexOfValue("boo").ShouldBe(2);                    // -> map.IndexOfValue("boo") should be 2 but was -1

Shouldly uses the code before the ShouldBe statement to report on errors, which makes diagnosing easier.

Read more about Shouldly and its features at https://docs.shouldly.org/.

Installation

Shouldly can be found here on NuGet and can be installed by copying and pasting the following command into your Package Manager Console within Visual Studio (Tools > NuGet Package Manager > Package Manager Console).

bash
Install-Package Shouldly

Alternatively if you're using .NET Core then you can install Shouldly via the command line interface with the following command:

bash
dotnet add package Shouldly

To have ShouldMatchApproved display a diff of the expected and actual files, you will need to install the Shouldly.DiffEngine package and configure it.

bash
Install-Package Shouldly.DiffEngine
csharp
ShouldMatchConfiguration.ShouldMatchApprovedDefaults.ConfigureDiffEngine();

Contributing

Contributions to Shouldly are very welcome. For guidance, please see CONTRIBUTING.md

Issues· 94 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#assertionshouldtestingunit

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.