0

After performing a test, we typically do an Assert.True(someCondition). When a condition check isn't necessary and just completion of the test is sufficient, I end a test with Assert.Pass().

I'm using FluentAssertions and have been doing true.Should().BeTrue();. That is starting to feel more like a hack and not in the correct spirit of the library.

Is there some other Fluent syntax I could use to accomplish .Pass() intention?

-Update: Based on feedback, there is nothing wrong with using .Pass() from XUnit or NUnit when using primarily FluentAssertions.

BillRob
  • 4,659
  • 4
  • 26
  • 38

1 Answers1

3

There isn't any equivalent to Assert.Pass() in Fluent Assertions. true.Should().BeTrue() is a tautology and a weaker statement than Assert.Pass(). So between those two I would continue using Assert.Pass().

Another way to explicitly state in code that running to completion is success, is saying that no exceptions should occur.

// Arrange
var subject = ...

// Act
var act = () => subject.CalculateTaxes();

// Assert
act.Should().NotThrow<Exception>();

For more examples on how to assert on exceptions, see https://fluentassertions.com/exceptions/.

A third way is to simply abandon the requirement of an explicit assertion, this can e.g. be captured in the method name, e.g. calculating_taxes_does_not_throw.

Jonas Nyrup
  • 2,376
  • 18
  • 25
  • We are moving to `FluentAssertions` so `Assert.Pass()` isn't an option anymore. Also these are more integrations tests so if step1(), step2(), step3() all work an no exceptions are thrown, we should be good. `true.Should().NotThrow()` is better conceptually, but of course isn't exactly what I'm looking for. – BillRob Dec 21 '22 at 17:46
  • 1
    If you continue using NUnit as the test framework, there's nothing wrong in using `Assert.Pass()`. Fluent Assertions isn't a complete replacement, but an addition. – Jonas Nyrup Dec 22 '22 at 22:12