Skip to content

agoda-com/Shouldly.FromAssert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shouldly.FromAssert

NuGet License

Because life's too short for hard-to-read assertions! 🔍

What is this?

Shouldly.FromAssert is a Roslyn analyzer that helps you migrate from traditional NUnit assertions to the more human-readable Shouldly library. It's like having a friendly code review buddy who's really into making tests more readable (but doesn't drink your coffee).

Features

  • Automatically detects NUnit assertions and suggests Shouldly alternatives
  • Provides code fixes to transform assertions with a single click
  • Supports a wide range of assertion types:
    • Basic assertions (Assert.AreEqualShouldBe)
    • String assertions (StringAssert.ContainsShouldContain)
    • Collection assertions (CollectionAssert.ContainsShouldContain)
    • Type assertions (Assert.IsInstanceOfShouldBeOfType)
    • And many more!

Installation

dotnet add package Shouldly.FromAssert

Usage

  1. Install the package
  2. Write your tests as usual with NUnit
  3. Look for the analyzer suggestions (they'll appear as warnings)
  4. Click the lightbulb 💡 or press (Alt+Enter or Ctrl+. depending on the IDE religeon you practice)
  5. Select "Convert to Shouldly"
  6. Watch your assertions transform into beautiful, readable Shouldly statements

Before and After

// Before: 😕
Assert.That(contestant, Is.EqualTo(1337));
CollectionAssert.Contains(contestants, winner);
StringAssert.StartsWith("Hello", greeting);

// After: 😊
contestant.ShouldBe(1337);
contestants.ShouldContain(winner);
greeting.ShouldStartWith("Hello");

Supported Conversions

Here are some examples of the transformations this analyzer can perform:

NUnit Shouldly
Assert.That(x, Is.EqualTo(y)) x.ShouldBe(y)
Assert.IsTrue(x > 10) (x > 10).ShouldBeTrue()
Assert.IsNull(x) x.ShouldBeNull()
CollectionAssert.Contains(list, item) list.ShouldContain(item)
StringAssert.StartsWith("Hi", str) str.ShouldStartWith("Hi")
Assert.Throws<ArgumentException>(() => method()) Should.Throw<ArgumentException>(() => method())

And many more! Check out the tests for a complete list of supported conversions.

Contributing

Found a bug? Have a suggestion? Want to add support for more assertions? We'd love your help! Please feel free to:

  1. Open an issue
  2. Submit a pull request
  3. Start a discussion
  4. Share your success stories

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

  • The awesome Shouldly team for making assertions more human
  • The Roslyn team for making this possible
  • Coffee ☕, for making developers possible

Made with 💚 by Agoda

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •