Skip to content

Latest commit

 

History

History
35 lines (31 loc) · 2.99 KB

README.md

File metadata and controls

35 lines (31 loc) · 2.99 KB

AppVeyor CircleCI CodeCov BetterCodeHub

AssertNet

Description

AssertNet is a fluent assertion library for multiple different .NET testing frameworks (xUnit, NUnit, MSTest) and the mocking framework Moq. The library is heavily inspired by AssertJ, a fluent assertion library for Java. The project originated from a personal frustration caused by a lack of a size assertion in the xUnit framework and my love for AssertJ. Currently most of the most common AssertJ assertions are included in AssertNet, but more advanced assertions are yet to be added. The package for Moq simply adds sugared assertions that look similar to the assertions in the other packages to have more consitensy in the way your tests look like.

Downloads

Currently there are multiple different NuGet packages available (for different frameworks):
AssertNet NuGet
AssertNet.Moq NuGet

There is also a third NuGet package available: AssertNet.Core NuGet, which contains all implementations of the custom assertions. This package can be used for adding support to other .NET testing frameworks. More information about this will be available on the wiki.

Usage

Grab one of the available version mentioned in the Downloads section above.
Add the following line to the test files where you intend to use AssertNet depending on your version:

using static AssertNet.Assertions;

For Moq:

using static AssertNet.Moq.Assertions;

Start writing your new assertions:

AssertThat(3).IsEqualTo(3);
AssertThat(() => DoWackyStuff()).ThrowsException<EvilException>().HasMessage("Something bad went wrong.");
AssertThat("Hello world!").StartsWith("Hello");
AssertThat(new int[] { 1, 2, 3 }).HasSize(3).ContainsExactlyInAnyOrder(2, 3, 1);
AssertThat(someMock).HasInvoked(x => x.SomeStubbedFunction()).Once();

More code examples will be supplied on the wiki.