Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would be an equivalent of Nunit's Assert.That in Xunit?

I know how to write this using Nunit,

Assert.That(exception, Is.InstanceOfType(typeof(TypeNotRegisteredException)));

How can I write the same thing using in Xunit, as Xunit does not have Assert.That.

like image 415
DoodleKana Avatar asked Jun 04 '13 04:06

DoodleKana


People also ask

How do you assert two objects are equal in xUnit?

You'll have to implement IEquatable<T> for your objects, and then Assert. Equals will work. Assert. Same() compares by reference; it asserts that Obj1 and Obj2 are the same object rather than just looking the same.

What is assert in xUnit?

In xUnit and many other testing frameworks, assertion is the mean that we conduct our test. In other word we assert an expectation that something is true about a piece of code. There are many different types of assertion in xUnit that we can use.

What is better NUnit or xUnit?

As far as NUnit vs. XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

What is assert that in NUnit?

Asserts that a condition is true. If the condition is false the method throws an AssertionException. That(Object, IResolveConstraint) Apply a constraint to an actual value, succeeding if the constraint is satisfied and throwing an assertion exception on failure.


1 Answers

You might be looking for:

Assert.IsType<TypeNotRegisteredException>(exception);

Let me know if this is close to what you're looking for.

like image 198
Matt Wilson Avatar answered Nov 15 '22 19:11

Matt Wilson