📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Which assertion library would you use in a .NET test project in 2026? Explain what happened to FluentAssertions' licence, compare the alternatives (AwesomeAssertions, Shouldly, the framework's built-in asserts), and tell me how you'd decide.

Covers the FluentAssertions v8 move to a commercial Xceed licence, the AwesomeAssertions fork, Shouldly, built-in xUnit/NUnit/MSTest asserts, structural equivalence, failure-message quality and how to choose and migrate.

Intermediate Theory Intermediate assertions fluentassertions licensing shouldly testing xunit

🎯 Key points

  • FluentAssertions v8 (January 2025) moved from Apache 2.0 to a commercial Xceed licence: paid per developer for commercial use, free only for non-commercial/open source
  • FluentAssertions 7.x stays Apache 2.0 with critical fixes only
  • AwesomeAssertions is the Apache 2.0 community fork, close to a drop-in rename
  • Shouldly (permissive licence) and built-in asserts are free alternatives
  • xUnit Assert.Equivalent (2.5+ and v3) / NUnit Is.EquivalentTo cover structural comparison
  • Judge by failure-message quality, licence risk, community support and dependency count, not syntax taste
  • Pin the major version so an automated update cannot pull in a commercial licence

⏱ 30-second answer

As of November 2026: FluentAssertions 8, released in January 2025, moved from Apache 2.0 to a commercial Xceed licence. Commercial use needs a paid per-developer licence; it is free only for non-commercial and open-source work. Version 7.x stays Apache 2.0 and gets critical fixes only. The community answer was AwesomeAssertions, an Apache 2.0 fork that is close to a namespace rename.

For a new commercial project I'd pick one of:

  • Built-in asserts (Assert.Equal, xUnit's Assert.Equivalent, available since xUnit 2.5 and in v3): no extra dependency, good enough messages.
  • Shouldly or AwesomeAssertions: readable ShouldBe/Should().Be() and excellent diffs for objects and collections.

The trade-off is readability and diff quality versus another dependency with licence risk and an uncertain maintenance future. Whatever you choose, pin the major version so a bot can't upgrade you into a paid licence.

🗣 Full answer (senior)

How I would answer this in an interview

"An assertion library has one job: when a test fails, tell me exactly what was different, fast. The framework asserts like xUnit's Assert.Equal do that well for simple values, and xUnit now has Assert.Equivalent for comparing object graphs by their properties. Libraries like FluentAssertions became popular because the syntax reads like a sentence and the failure messages for collections and objects were excellent.

The landscape changed in January 2025. FluentAssertions version 8 was released under a commercial licence after a partnership with Xceed. It's free for open-source and non-commercial use, but a company using it needs a paid licence per developer. Version 7 stays on Apache 2.0 and only gets critical fixes. The community forked the last open code into AwesomeAssertions, which keeps the same fluent API under Apache 2.0, so migrating is mostly a package and namespace swap. Shouldly is the other popular option, with a result.ShouldBe(expected) style and good messages that include the expression text.

How I decide: first, licence risk. A Dependabot PR that bumps FluentAssertions from 7 to 8 silently creates a compliance problem, so I either pin with Central Package Management or move off it. Second, failure-message quality on the things we compare most, which in APIs is usually DTOs and collections. Third, fewer dependencies is better. For a new service I'm happy with built-in asserts plus Assert.Equivalent, and Verify for big payloads. The mistake I see is choosing on syntax taste; the real costs are licences and unreadable failures."


The options in 2026

Library Licence Style Notes
FluentAssertions 8.x Xceed commercial (free non-commercial) x.Should().Be(y) Paid per developer for commercial use
FluentAssertions 7.x Apache 2.0 same Critical fixes only, no new features
AwesomeAssertions Apache 2.0 same Community fork; namespace AwesomeAssertions
Shouldly Permissive open source x.ShouldBe(y) Messages show the source expression
xUnit Assert Apache 2.0 Assert.Equal(y, x) Assert.Equivalent for object graphs
NUnit Assert.That MIT Assert.That(x, Is.EqualTo(y)) Rich constraint model
Verify MIT snapshot Best for large outputs, not small values

Decision guide

Situation Choice
Existing suite on FA 7, commercial Pin to 7.x now; plan a move to AwesomeAssertions
Existing suite on FA 8, commercial Buy licences or migrate; don't ignore it
New service, small team Built-in asserts + Assert.Equivalent
Heavy object and collection comparison AwesomeAssertions or Shouldly
Large JSON or HTML outputs Verify snapshots

Production example

A consultancy found 14 client repositories had been auto-upgraded to FluentAssertions 8 by Dependabot over three months. Licence scanning flagged it during a client audit. They pinned to 7.x through Central Package Management in a day, then moved to AwesomeAssertions with a scripted namespace replace; 9,000 tests passed unchanged apart from 12 that relied on removed APIs.

🔍 What the interviewer is checking

Checks awareness of recent ecosystem changes and whether the candidate weighs licence risk and failure diagnostics, not just syntax.

Green flags

  • States the FluentAssertions v8 licence change accurately and what 7.x still offers
  • Names alternatives (AwesomeAssertions, Shouldly, built-in) with their licences
  • Talks about failure-message quality and structural equivalence
  • Mentions pinning or licence scanning

Red flags

  • Unaware of the licence change or says it doesn't matter for tests
  • Uses Assert.True(a == b) style assertions
  • Picks a library purely on taste

📚 Learn in depth

1. What an assertion really is

An assertion is a method that throws an exception when a condition is false. The framework catches it, marks the test failed and prints the message:

 test method
    |-- Act
    |-- Assert -> condition false -> throw XunitException(message)
                                         |
                    runner catches -> test failed + message + stack trace

Every library is just a different way of building that message. Quality differences come from how well it describes the difference (which property, which index, expected versus actual).

2. Structural equivalence

Comparing two DTOs with Assert.Equal uses Equals. Records get value equality for free; classes don't. Equivalence assertions walk both object graphs by reflection and compare member by member:

expected.Customer.Address.Postcode = "2000"
actual.Customer.Address.Postcode   = "2001"   <- reported path

xUnit's Assert.Equivalent(expected, actual, strict: false) ignores extra members on actual unless strict is true. FluentAssertions / AwesomeAssertions BeEquivalentTo lets you exclude members and control ordering.

3. Why licence changes matter in tests

Test dependencies aren't shipped to customers, but licences apply to use, not only distribution. A commercial licence that is required "for commercial use" covers your developers running tests on company machines and CI. Licence scanners (GitHub dependency review, Snyk, Mend) flag these packages, and audits ask about them.

4. Forks and API compatibility

A fork such as AwesomeAssertions starts from the last Apache 2.0 commit, so the API is almost identical. Migration is usually: swap the package, replace using FluentAssertions;, fix the few APIs that diverged. Over time forks drift, so read release notes before assuming a drop-in.

5. Pinning versions

With Central Package Management (Directory.Packages.props) you set the version once. A Dependabot ignore rule for major versions stops the bot proposing a 7 to 8 jump.

Try it yourself

  1. Compare two DTO classes (not records) with Assert.Equal and with Assert.Equivalent; read both failure messages.
  2. Write the same failing collection assertion with built-in asserts, Shouldly and AwesomeAssertions, and compare the diffs.
  3. Add Directory.Packages.props to a solution and pin your assertion library.
  4. Add a Dependabot ignore rule for major versions of that package.
  5. Run dotnet list package --include-transitive and look for any package whose licence you don't know.

💻 Code

The same test with built-in xUnit asserts and with Shouldly, plus version pinning:

// QuoteService.cs (code under test)
namespace Shop.Quotes;

public sealed class QuoteLine(string sku, int quantity, decimal unitPrice)
{
    public string Sku { get; } = sku;
    public int Quantity { get; } = quantity;
    public decimal UnitPrice { get; } = unitPrice;
}

public sealed class Quote(string customer, IReadOnlyList<QuoteLine> lines)
{
    public string Customer { get; } = customer;
    public IReadOnlyList<QuoteLine> Lines { get; } = lines;
    public decimal Total => Lines.Sum(l => l.Quantity * l.UnitPrice);
}

public static class QuoteService
{
    public static Quote Create(string customer) =>
        new(customer, [new QuoteLine("SKU-1", 2, 10m), new QuoteLine("SKU-2", 1, 5.5m)]);
}
// QuoteServiceTests.cs (xunit.v3 + Shouldly)
using Shop.Quotes;
using Shouldly;
using Xunit;

namespace Shop.Quotes.Tests;

public sealed class QuoteServiceTests
{
    [Fact]
    public void Built_in_equivalent_compares_by_members()
    {
        var quote = QuoteService.Create("Acme");

        // Quote is a class without value equality, so Assert.Equal would compare references.
        Assert.Equivalent(
            new { Customer = "Acme", Lines = new[] { new { Sku = "SKU-1", Quantity = 2 }, new { Sku = "SKU-2", Quantity = 1 } } },
            quote);
        Assert.Equal(25.5m, quote.Total);
    }

    [Fact]
    public void Shouldly_reads_naturally()
    {
        var quote = QuoteService.Create("Acme");

        quote.Customer.ShouldBe("Acme");
        quote.Lines.Select(l => l.Sku).ShouldBe(["SKU-1", "SKU-2"]);
        quote.Total.ShouldBe(25.5m);
    }
}
<!-- Directory.Packages.props: pin versions so a bot cannot jump a licence boundary -->
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="xunit.v3" Version="4.0.0" />
    <PackageVersion Include="Shouldly" Version="4.3.0" />
    <!-- If you must stay on FluentAssertions for now: the last Apache 2.0 line. -->
    <PackageVersion Include="FluentAssertions" Version="[7.2.0, 8.0.0)" />
  </ItemGroup>
</Project>

⚠ Common mistakes

  • Mistake: Letting Dependabot or Renovate upgrade FluentAssertions to 8.x automatically. Why it is wrong: It moves a commercial project onto a licence that requires payment. Instead: Pin to [7.x, 8.0.0) or migrate to AwesomeAssertions, Shouldly or built-in asserts.
  • Mistake: Assuming test-only packages don't need licence review. Why it is wrong: Licences cover use on developer machines and CI, not just shipped binaries. Instead: Include test projects in licence scanning.
  • Mistake: Using Assert.Equal on classes without value equality. Why it is wrong: It compares references and fails with a useless message. Instead: Use records, Assert.Equivalent, or an equivalence assertion.
  • Mistake: Using Assert.True(a == b). Why it is wrong: The failure message just says "expected True". Instead: Use Assert.Equal(expected, actual) so the message shows both values.
  • Mistake: Swapping expected and actual in Assert.Equal. Why it is wrong: Failure messages become misleading. Instead: Expected first in xUnit, or use a fluent style where the order is obvious.
  • Mistake: Mixing two or three assertion libraries in one solution. Why it is wrong: Inconsistent style and more dependencies to review. Instead: Pick one and add an analyser or code review rule.
  • Mistake: Asserting on huge object graphs field by field. Why it is wrong: Tests become long and miss new fields. Instead: Use Verify snapshots for large outputs.

🏛 Senior insight: trade-offs

Assertion libraries are a low-value, high-churn dependency: they improve readability but rarely change what you can test. After the FluentAssertions licence change I treat them like any other third-party dependency: check the licence, pin the major version and prefer fewer packages. Built-in asserts have caught up enough (Assert.Equivalent, collection asserts, Assert.Multiple in xUnit and NUnit) that many teams no longer need a library.

Option When it fits Cost When not to
Built-in asserts New projects, minimal dependencies Slightly less readable Heavy graph comparisons with exclusions
AwesomeAssertions Migrating from FluentAssertions Fork may diverge; smaller team When you'd rather drop the dependency
Shouldly Readable assertions, good messages Different API to learn Suites already on the fluent Should() style
FluentAssertions 8 + licence Teams happy to pay for support Per-developer cost, procurement Projects with no budget or procurement path

Measure by reading real failure messages from CI: if a developer can't tell what broke without re-running locally, the assertions aren't doing their job.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions large DTOs or JSON responses. Why: Checks judgement about assertion strategy for large outputs.
    How to answer

    Use snapshot testing when the output is large or structured and you care about all of it: an API response, a generated email, source generator output, an OpenAPI document. Verify serialises the result to a .verified.txt file that is committed with the code. On the next run it compares the new output and, if anything differs, writes a .received.txt file, fails the test and shows a diff.

    Verify scrubs volatile values such as Guids and dates by default. When a change is intended, you review the diff and accept it, and the updated snapshot is reviewed again in the pull request.

    I keep explicit assertions for the one or two values that are the business rule, such as "GST is 10%". The trade-off is that snapshots replace a lot of assertion code, but if people accept them without reading, they only detect change. They stop checking correctness.

  2. When: Candidate mentions Dependabot or the licence change. Why: Checks supply-chain governance in a .NET solution.
    How to answer

    A NuGet package version is immutable, so a licence can only change when you take a new version. The job is to control which versions get in:

    • Central Package Management (Directory.Packages.props) puts every version in one file that gets reviewed, and lock files pin transitive packages too.
    • Dependabot ignore rules for major versions of sensitive packages. Majors are where licences change: FluentAssertions 8 moved to a paid commercial licence in January 2025.
    • A CI licence gate such as GitHub's dependency-review-action with allow-licenses, or the nuget-license tool, against an allow-list. It also fails on unknown licences.

    Test and build packages get the same review as production ones. The trade-off is some friction on every upgrade, in exchange for never finding a commercial licence during an audit.

More in .NET Testing Tools

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me