Skip to content

XUnit and FluentAssertions

Theory

using XUnit;

[Theory]
[InlineData("param1","param2")]
[InlineData("param1a","param2a")]
public void TestVariousThings(string parameter1, string parameter2) 
{
    ...
}

Testing For Values

using FluentAssertions;
using XUnit;

[Fact]
public void MyTest() 
{
    var personName = "John Smith";
    var person = new Person(personName);
    person.Name.Should().be(personName);

// without Fluent Assertions this work be...
    Assert.Equal(personName, person.Name);
}


Testing for Exceptions

using FluentAssertions;
using XUnit;

[Fact]
public void MyTest() 
{
    Action act () => MyFunctionToTest(param1, param2);
    act.Should.Throw<SomeExceptionType>().WithMessage("Exception message");
}