Martin
Martin

Reputation: 24316

Nunit: Which assert to use to ensure that everything passed at the end of my unit test?

I have written a test and I just want to ensure that everything passed and no exceptions were thrown ?

Is there some kind of special Assert to use at the end of the test?

What are the recommendations here?

Thanks in advance

Upvotes: 2

Views: 347

Answers (3)

Dennis Doomen
Dennis Doomen

Reputation: 8909

If you use Fluent Assertions (which your tag suggests), you can do:

Action act = () => MethodThatShouldNotThrowAnError();
act.ShouldNotThrow();

Upvotes: 1

Alexander Stepaniuk
Alexander Stepaniuk

Reputation: 6438

Just don't write any return statements in the test. Then the fact that test is finished with no exception will exactly mean that everithing in the test is passed.

Upvotes: -1

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 15158

The unit test will fail if an exception is thrown anyway. That is of course unless you're expecting it to fail, in which case you can capture and assert it, something like:

var exception = Assert.Throws<Exception>(() => MethodThatShouldThrowAnError());
Assert.AreEqual("Not Brilliant", exception.Message);

Upvotes: 1

Related Questions