Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xUnit : Mutiple Assertions or Soft Assert

Tags:

c#

xunit

specflow

How can I find Multiple Assertions or Soft Assert in xUnit? I found Nunit has below ability, trying to find similar options in xUnit.

Assert.Multiple(() =>
 {
   Assert.AreEqual(expectedResult1, actualResult1, "Mismatch in Score1!");
   Assert.AreEqual(expectedResult2, actualResult2, "Mismatch in Score2!");
   Assert.AreEqual(expectedResult3, actualResult3, "Mismatch in Score3!");
  });
like image 350
Kingsly Bose Avatar asked Nov 25 '19 12:11

Kingsly Bose


1 Answers

As of xUnit 2, it does not exist.

There are plenty of things we could do, but for many reasons we choose not to. This reasons include: (a) implementation and maintenance cost; (b) competing priorities; (c) philosophical objections to features.

In this case, you're running afoul of (c). We do not believe that a unit testing framework should ever run more than one failing assertion.

xUnit is in general much more opinionated than NUnit, and won't include things which NUnit supports, for ideological reasons.


It looks like xUnit 3 will support this, using Assert.Multiple.

like image 90
canton7 Avatar answered Sep 27 '22 22:09

canton7