Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Assert.True and Assert.IsTrue in NUnit?

Tags:

assert

nunit

Is there any differences between those two?

like image 492
Vlad Titov Avatar asked Sep 10 '12 13:09

Vlad Titov


People also ask

What is assert IsTrue?

IsTrue(Boolean, String) Tests whether the specified condition is true and throws an exception if the condition is false. IsTrue() Tests whether the specified condition is true and throws an exception if the condition is false.

What is assert in NUnit?

Assertions are central to unit testing in any of the xUnit frameworks, and NUnit is no exception. NUnit provides a rich set of assertions as static methods of the Assert class. If an assertion fails, the method call does not return and an error is reported.


2 Answers

No difference. Assert.True() and others (without Is) were added since v2.5.

From documentation for the version 2.5: (nunit v2.5)

Two forms are provided for the True, False, Null and NotNull conditions. The "Is" forms are compatible with earlier versions of the NUnit framework, while those without "Is" are provided for compatibility with NUnitLite

BTW, Disassembled nunit.framework.dll (using ILSPY)

public static void IsTrue(bool condition) {     Assert.That(condition, Is.True, null, null); }  public static void True(bool condition) {     Assert.That(condition, Is.True, null, null); } 
like image 93
sll Avatar answered Oct 01 '22 20:10

sll


There does not seem to be any implementational difference. Looking at the source code for the most recent version here, the True, IsTrue and That are all implemented in the same way when the argument lists are the same:

public static void True(bool condition, string message, params object[] args) {     Assert.That(condition, Is.True, message, args); } ... public static void IsTrue(bool condition, string message, params object[] args) {     Assert.That(condition, Is.True, message, args); } ... static public void That(bool condition, string message, params object[] args) {     Assert.That(condition, Is.True, message, args); } 

The overloaded methods are implemented analogously.

like image 45
Anders Gustafsson Avatar answered Oct 01 '22 19:10

Anders Gustafsson