General tips:

  • If your assertion ends with Should().BeTrue(), there is most likely a better way to write it.
  • By having Should() as early as possible in the assertion, we are able to include more information in the failure messages.

Improved assertions

The examples below show how you might improve your existing assertions to both get more readable assertions and much more informative failure messages.

If you see something missing, please consider submitting a pull request.

Collections

Assertion Improvement
actual.Any().Should().BeTrue();

actual.Should().NotBeEmpty();

Expected True, but found False.

Expected collection not to be empty.

Assertion Improvement
actual.Any().Should().BeFalse();

actual.Should().BeEmpty();

Expected False, but found True.

Expected collection to be empty, but found {SomeProperty: 0, OtherProperty: }.

Assertion Improvement
actual.Any(x => x.SomeProperty).Should().BeTrue();

actual.Should().Contain(x => x.SomeProperty);

Expected True, but found False.

Collection {SomeProperty: 0, OtherProperty: Actual} should have an item matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass5_0).expectedValue).

Assertion Improvement
actual.Any(x => x.SomeProperty).Should().BeFalse();

actual.Should().NotContain(x => x.SomeProperty);

Expected False, but found True.

Expected Collection {SomeProperty: 0, OtherProperty: Unexpected} to not have any items matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass7_0).unexpectedValue).

Assertion Improvement
actual.All(x => x.SomeProperty).Should().BeTrue();

// now fails on empty collection;
actual.Should().OnlyContain(x => x.SomeProperty)

Expected True, but found False.

Expected collection to contain only items matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass9_0).expectedValue), but {SomeProperty: 0, OtherProperty: Actual} do(es) not match.

Assertion Improvement
actual.Contains(expected).Should().BeTrue();

actual.Should().Contain(expected);

Expected True, but found False.

Expected collection {"Actual"} to contain "Expected".

Assertion Improvement
actual.Should().Contain(item)
    .And.Contain(anotherItem);

actual.Should().Contain(new [] { item, anotherItem});

Expected collection {1, 2, 3, 4} to contain 13.

Expected collection {1, 2, 3, 4} to contain {13, 37}, but could not find {13, 37}.

Assertion Improvement
actual.Should().NotContain(item)
    .And.NotContain(anotherItem);

actual.Should().NotContain(new [] { item, anotherItem});

Expected collection {1, 2, 3, 4} to not contain 2.

Expected collection {1, 2, 3, 4} to not contain {2, 3}, but found {2, 3}.

Assertion Improvement
actual.Contains(unexpected).Should().BeFalse();

actual.Should().NotContain(unexpected);

Expected False, but found True.

Expected collection {"Expected"} to not contain "Expected".

Assertion Improvement
actual.Any(x => x == unexpected).Should().BeFalse();

actual.Should().NotContain(unexpected);

Expected False, but found True.

Expected collection {"Unexpected"} to not contain "Unexpected".

Assertion Improvement
actual.Count().Should().Be(k);

actual.Should().HaveCount(k);

Expected value to be 2, but found 3.

Expected collection to contain 2 item(s), but found 3.

Assertion Improvement
actual.Count().Should().BeGreaterThan(k);

actual.Should().HaveCountGreaterThan(k);

Expected a value greater than 4, but found 3.

Expected collection to contain more than 4 item(s), but found 3.

Assertion Improvement
actual.Count().Should().BeGreaterOrEqualTo(k);

actual.Should().HaveCountGreaterOrEqualTo(k);

Expected a value greater or equal to 4, but found 3.

Expected collection to contain at least 4 item(s), but found 3.

Assertion Improvement
actual.Count().Should().BeLessThan(k);

actual.Should().HaveCountLessThan(k);

Expected a value less than 2, but found 3.

Expected collection to contain fewer than 2 item(s), but found 3.

Assertion Improvement
actual.Count().Should().BeLessOrEqualTo(k);

actual.Should().HaveCountLessOrEqualTo(k);

Expected a value less or equal to 2, but found 3.

Expected collection to contain at most 2 item(s), but found 3.

Assertion Improvement
actual.Count().Should().NotBe(k);

actual.Should().NotHaveCount(k);

Did not expect 3.

Expected collection to not contain 3 item(s), but found 3.

Assertion Improvement
actual.Should().HaveCount(1);

actual.Should().ContainSingle();

Expected collection to contain 1 item(s), but found 3.

Expected collection to contain a single item, but found {"", "", ""}.

Assertion Improvement
actual.Should().HaveCount(0);

actual.Should().BeEmpty();

Expected collection to contain 0 item(s), but found 3.

Expected collection to be empty, but found {"", "", ""}.

Assertion Improvement
actual.Should().HaveCount(expected.Count());

actual.Should().HaveSameCount(expected);

Expected collection to contain 2 item(s), but found 3.

Expected collection to have 2 item(s), but found 3.

Assertion Improvement
actual.Count().Should().NotBe(unexpected.Count());

actual.Should().NotHaveSameCount(unexpected);

Did not expect 2.

Expected collection to not have 2 item(s), but found 2.

Assertion Improvement
actual.Where(x => x.SomeProperty).Should().NotBeEmpty();

actual.Should().Contain(x => x.SomeProperty);

Expected collection not to be empty.

Collection {SomeProperty: 0, OtherProperty: Actual} should have an item matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass39_0).expectedValue).

Assertion Improvement
actual.Where(x => x.SomeProperty).Should().BeEmpty();

actual.Should().NotContain(x => x.SomeProperty);

Expected collection to be empty, but found {SomeProperty: 0, OtherProperty: Expected}.

Expected Collection {SomeProperty: 0, OtherProperty: Expected} to not have any items matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass41_0).expectedValue).

Assertion Improvement
actual.Where(x => x.SomeProperty).Should().HaveCount(1);

actual.Should().ContainSingle(x => x.SomeProperty);

Expected collection to contain 1 item(s), but found 0.

Expected collection to contain a single item matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass43_0).expectedValue), but no such item was found.

Assertion Improvement
actual.Should().OnlyContain(e => !e.SomeProperty);

actual.Should().NotContain(x => x.SomeProperty);

Expected collection to contain only items matching (x.OtherProperty != value(UnitTests2.CollectionTests+<>c__DisplayClass44_0).unexpectedValue), but {SomeProperty: 0, OtherProperty: Unexpected} do(es) not match.

Expected Collection {SomeProperty: 0, OtherProperty: Unexpected} to not have any items matching (x.OtherProperty == value(UnitTests2.CollectionTests+<>c__DisplayClass45_0).unexpectedValue).

Assertion Improvement
actual.Should().NotBeNull().And.NotBeEmpty();

actual.Should().NotBeNullOrEmpty();

Expected collection not to be empty.

Expected collection not to be empty.

Assertion Improvement
actual.ElementAt(k).Should().Be(expected);

actual.Should().HaveElementAt(k, expected);

Expected string to be 
"Expected" with a length of 8, but 
"Unexpected" has a length of 10.

Expected "Expected" at index 0, but found "Unexpected".

Assertion Improvement
actual[k].Should().Be(expected);

actual.Should().HaveElementAt(k, expected);

Expected string to be 
"Expected" with a length of 8, but 
"Unexpected" has a length of 10.

Expected "Expected" at index 0, but found "Unexpected".

Assertion Improvement
actual.Skip(k).First().Should().Be(expected);

actual.Should().HaveElementAt(k, expected);

Expected string to be 
"Expected" with a length of 8, but 
"Unexpected" has a length of 10.

Expected "Expected" at index 1, but found "Unexpected".

Assertion Improvement
actual.OrderBy(x => x.SomeProperty)
    .Should().Equal(actual);

actual.Should().BeInAscendingOrder(x => x.SomeProperty);

Expected collection to be equal to {SomeProperty: 2, OtherProperty: , SomeProperty: 1, OtherProperty: }, but {SomeProperty: 1, OtherProperty: , SomeProperty: 2, OtherProperty: } differs at index 0.

Expected collection {SomeProperty: 2, OtherProperty: , SomeProperty: 1, OtherProperty: } to be ordered" by SomeProperty" and result in {SomeProperty: 1, OtherProperty: , SomeProperty: 2, OtherProperty: }.

Assertion Improvement
actual.OrderByDescending(x => x.SomeProperty)
    .Should().Equal(actual);

actual.Should().BeInDescendingOrder(x => x.SomeProperty);

Expected collection to be equal to {SomeProperty: 1, OtherProperty: , SomeProperty: 2, OtherProperty: }, but {SomeProperty: 2, OtherProperty: , SomeProperty: 1, OtherProperty: } differs at index 0.

Expected collection {SomeProperty: 1, OtherProperty: , SomeProperty: 2, OtherProperty: } to be ordered" by SomeProperty" and result in {SomeProperty: 2, OtherProperty: , SomeProperty: 1, OtherProperty: }.

Assertion Improvement
actual.Select(e1 => e1.SomeProperty).Should()
    .Equal(expected.Select(e2 => e2.SomeProperty));

actual.Should()
    .Equal(expected, 
        (e1, e2) => e1.SomeProperty == e2.SomeProperty);

Expected collection to be equal to {"Expected", "Expected"}, but {"Actual", "Actual"} differs at index 0.

Expected collection to be equal to {SomeProperty: 1, OtherProperty: Expected, SomeProperty: 2, OtherProperty: Expected}, but {SomeProperty: 1, OtherProperty: Actual, SomeProperty: 2, OtherProperty: Actual} differs at index 0.

Assertion Improvement
actual.Intersect(expected).Should().BeEmpty();

actual.Should().NotIntersectWith(expected);

Expected collection to be empty, but found {SomeProperty: 1, OtherProperty: Expected}.

Did not expect collection to intersect with {SomeProperty: 1, OtherProperty: Expected}, but found the following shared items {SomeProperty: 1, OtherProperty: Expected}.

Assertion Improvement
actual.Intersect(expected).Should().NotBeEmpty();

actual.Should().IntersectWith(expected);

Expected collection not to be empty.

Expected collection to intersect with {SomeProperty: 1, OtherProperty: Expected}, but {SomeProperty: 1, OtherProperty: Actual} does not contain any shared items.

Assertion Improvement
actual.Select(x => x.SomeProperty)
    .Should().NotContainNulls();

actual.Should().NotContainNulls(e => e.OtherProperty);

Expected collection not to contain nulls, but found one at index 0.

Expected collection not to contain <null>s on e.OtherProperty, but found {SomeProperty: 1, OtherProperty: }.

Assertion Improvement
actual.Should().HaveSameCount(actual.Distinct());

actual.Should().OnlyHaveUniqueItems();

Expected collection to have 1 item(s), but found 2.

Expected collection to only have unique items, but item SomeProperty: 1, OtherProperty:  is not unique.

Assertion Improvement
actual.Select(x => x.SomeProperty)
    .Should().OnlyHaveUniqueItems();

actual.Should().OnlyHaveUniqueItems(x => x.SomeProperty);

Expected collection to only have unique items, but item 1 is not unique.

Expected collection to only have unique items on x.SomeProperty, but item SomeProperty: 1, OtherProperty:  is not unique.

Assertion Improvement
// From the assertion it is unclear what is being tested.
actual.FirstOrDefault().Should().BeNull();

// The first element is null.
actual.Should().HaveElementAt(0, null);

Expected string to be <null>, but found "".

Expected <null> at index 0, but found "".

Comparable and Numerics

Assertion Improvement
actual.Should().BeGreaterThan(0);

actual.Should().BePositive();

Expected a value greater than 0, but found -1.

Expected positive value, but found -1

Assertion Improvement
actual.Should().BeLessThan(0);

actual.Should().BeNegative();

Expected a value less than 0, but found 1.

Expected negative value, but found 1

Assertion Improvement
(lower <= actual && actual <= upper).Should().BeTrue();

actual.Should().BeInRange(lower, upper);

Expected True, but found False.

Expected value to be between 1 and 5, but found 6.

Assertion Improvement
(lower <= actual && actual <= upper).Should().BeFalse();

actual.Should().NotBeInRange(lower, upper);

Expected False, but found True.

Expected value to not be between 1 and 5, but found 4.

Assertion Improvement
actual.Should().BeGreaterOrEqualTo(lower)
    .And.BeLessOrEqualTo(upper);

actual.Should().BeInRange(lower, upper);

Expected a value less or equal to 5, but found 6.

Expected value to be between 1 and 5, but found 6.

Assertion Improvement
Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta);

actual.Should().BeApproximately(expected, delta);

Expected a value less or equal to 1.0, but found 2.0.

Expected value 6.5 to approximate 4.5 +/- 1.0, but it differed by 2.0.

DateTimes

Assertion Improvement
actual.Date.Should().Be(expected.Date);

actual.Should().BeSameDateAs(expected);

Expected date and time to be <2017-01-01>, but found <2017-01-02>.

Expected a date and time with date <2017-01-01>, but found <2017-01-02 21:00:00>.

Assertion Improvement
actual.Date.Should().NotBe(unexpected.Date);

actual.Should().NotBeSameDateAs(unexpected);

Expected date and time not to be <2017-01-01>, but it is.

Expected a date and time that does not have date <2017-01-01>, but found it does.

Dictionaries

Assertion Improvement
actual.ContainsKey(expected).Should().BeTrue();

actual.Should().ContainKey(expected);

Expected True, but found False.

Expected dictionary {[0, ]} to contain key 1.

Assertion Improvement
actual.ContainsKey(expected).Should().BeFalse();

actual.Should().NotContainKey(expected);

Expected False, but found True.

Dictionary {[0, ]} should not contain key 0, but found it anyhow.

Assertion Improvement
actual.ContainsValue(expected).Should().BeTrue();

actual.Should().ContainValue(expected);

Expected True, but found False.

Expected dictionary {[0, ]} to contain value "expected".

Assertion Improvement
actual.ContainsValue(expected).Should().BeFalse();

actual.Should().NotContainValue(expected);

Expected False, but found True.

Dictionary {[0, expected]} should not contain value "expected", but found it anyhow.

Assertion Improvement
actual.Should().ContainKey(expectedKey)
    .And.ContainValue(expectedValue);

actual.Should().Contain(expectedKey, expectedValue);

Expected dictionary {[0, ]} to contain value "expected".

Expected dictionary to contain value "expected" at key 0, but found "".

Assertion Improvement
actual.Should().ContainKey(expected.Key)
    .And.ContainValue(expected.Value);

actual.Should().Contain(expected);

Expected dictionary {[0, ]} to contain value "expected".

Expected dictionary to contain value "expected" at key 0, but found "".

Assertion Improvement
actual.Should().ContainKey(key1)
    .And.ContainKey(key2);

actual.Should().ContainKeys(key1, key2);

Expected dictionary {[0, a], [1, b]} to contain key 2.

Expected dictionary {[0, a], [1, b]} to contain key {1, 2}, but could not find {2}.

Assertion Improvement
actual.Should().NotContainKey(key1)
    .And.NotContainKey(key2);

actual.Should().NotContainKeys(key1, key2);

Dictionary {[2, c], [3, d]} should not contain key 2, but found it anyhow.

Expected dictionary {[2, c], [3, d]} to not contain key {2, 3}, but found {2, 3}.

Assertion Improvement
actual.Should().ContainValue(value1)
    .And.ContainValue(value2);

actual.Should().ContainValues(value1, value2);

Expected dictionary {[0, a], [1, b]} to contain value "c".

Expected dictionary {[0, a], [1, b]} to contain value {"c", "d"}, but could not find {"c", "d"}.

Assertion Improvement
actual.Should().NotContainValue(value1)
    .And.NotContainValue(value2);

actual.Should().NotContainValues(value1, value2);

Dictionary {[2, c], [3, d]} should not contain value "c", but found it anyhow.

Expected dictionary {[2, c], [3, d]} to not contain value {"c", "d"}, but found {"c", "d"}.

Exceptions

Assertion Improvement
Action act = () => func();

act.Should().ThrowExactly<InvalidOperationException>()
    .Which.Message.Should().Contain("expectedMessage");

Action act = () => func();

// using wildcards
act.Should().ThrowExactly<InvalidOperationException>()
    .WithMessage("*expectedMessage*");

Expected string "Problems, errorCode2 and more Problems" to contain "errorCode1".

Expected exception message to match the equivalent of 
"*errorCode1*", but 
"Problems, errorCode2 and more Problems" does not.

Nullables

Assertion Improvement
actual.HasValue.Should().BeTrue();

actual.Should().HaveValue();

Expected True, but found False.

Expected a value.

Assertion Improvement
actual.HasValue.Should().BeFalse();

actual.Should().NotHaveValue();

Expected False, but found True.

Did not expect a value, but found 1.

Strings

Assertion Improvement
actual.StartsWith(expectedPrefix).Should().BeTrue();

actual.Should().StartWith(expectedPrefix);

Expected True, but found False.

Expected string to start with 
"Expected", but 
"ActualString" differs near "Act" (index 0).

Assertion Improvement
actual.EndsWith(expectedSuffix).Should().BeTrue();

actual.Should().EndWith(expectedSuffix);

Expected True, but found False.

Expected string "ActualString" to end with "Expected".

Assertion Improvement
actual.Should().NotBeNull().And.NotBeEmpty();

actual.Should().NotBeNullOrEmpty();

Did not expect empty string.

Expected string not to be <null> or empty, but found "".

Assertion Improvement
string.IsNullOrEmpty(actual).Should().BeTrue();

actual.Should().BeNullOrEmpty();

Expected True, but found False.

Expected string to be <null> or empty, but found "Actual".

Assertion Improvement
string.IsNullOrEmpty(actual).Should().BeFalse();

actual.Should().NotBeNullOrEmpty();

Expected False, but found True.

Expected string not to be <null> or empty, but found "".

Assertion Improvement
string.IsNullOrWhiteSpace(actual).Should().BeTrue();

actual.Should().BeNullOrWhiteSpace();

Expected True, but found False.

Expected string to be <null> or whitespace, but found "Actual".

Assertion Improvement
string.IsNullOrWhiteSpace(actual).Should().BeFalse();

actual.Should().NotBeNullOrWhiteSpace();

Expected False, but found True.

Expected string not to be <null> or whitespace, but found " ".

Assertion Improvement
actual.Length.Should().Be(k);

actual.Should().HaveLength(k);

Expected value to be 4, but found 6.

Expected string with length 4, but found string "Actual" with length 6.

Assertion Improvement
actual.Should().Contain(item)
    .And.Contain(anotherItem);

actual.Should().ContainAll(item, anotherItem);

Expected string "chalk dirt mud" to contain "ruby".

Expected string "chalk dirt mud" to contain the strings: {"ruby", "diamond"}.

Assertion Improvement
actual.Should().NotContain(item)
    .And.NotContain(anotherItem);

actual.Should().NotContainAny(item, anotherItem);

Did not expect string "chalk ruby dirt diamond mud" to contain "ruby".

Did not expect the string "chalk ruby dirt diamond mud" to contain any of the strings: {"ruby", "diamond"}.

Assertion Improvement
actual.ToUpper().Should().Be(expected.ToUpper());

actual.Should().BeEquivalentTo(expected);

Expected string to be "SOME TEXT" with a length of 9, but "SOME WEIRD TEXT" has a length of 15.

Expected string to be equivalent to "some text" with a length of 9, but "sOmE WeIrD tExT" has a length of 15.

Types

Assertion Improvement
actual.GetType().Should().Be(typeof(T));

actual.Should().BeOfType<T>();

Expected type to be UnitTests2.MyClass, but found UnitTests2.MyIdenticalClass.

Expected type to be UnitTests2.MyClass, but found UnitTests2.MyIdenticalClass.

Assertion Improvement
actual.GetType().Should().NotBe(typeof(T));

actual.Should().NotBeOfType<T>();

Expected type not to be [UnitTests2.MyClass, UnitTests2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], but it is.

Expected type not to be [UnitTests2.MyClass, UnitTests2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], but it is.

Assertion Improvement
(actual is T).Should().BeTrue();

actual.Should().BeAssignableTo<T>();

Expected True, but found False.

Expected object to be assignable to UnitTests2.MyClass, but UnitTests2.MyIdenticalClass is not.

Assertion Improvement
(actual as T).Should().NotBeNull();

actual.Should().BeAssignableTo<T>();

Expected object not to be <null>.

Expected object to be assignable to UnitTests2.MyClass, but UnitTests2.MyIdenticalClass is not.

Assertion Improvement
(actual is T).Should().BeFalse();

actual.Should().NotBeAssignableTo<T>();

Expected False, but found True.

Expected object to not be assignable to UnitTests2.MyClass, but UnitTests2.MyClass is.

Assertion Improvement
(actual as T).Should().BeNull();

actual.Should().NotBeAssignableTo<T>();

Expected object to be <null>, but found SomeProperty: 1, OtherProperty: actual.

Expected object to not be assignable to UnitTests2.MyClass, but UnitTests2.MyClass is.