Is there any differences between those two?
Asked
Active
Viewed 1.5k times
2 Answers
57
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);
}

sll
- 61,540
- 22
- 104
- 156
-
1Do users have any preference for which to use? Or is there one that "should" be used? – dmeehan Mar 19 '15 at 11:41
-
2According to the next answer, the three implementations are exactly the same and all rely on Assert.That() So the best would be to directly use Assert.That()... sll's answer (here, in this post) is copied from the NUnit site: http://www.nunit.org/index.php?p=conditionAsserts&r=2.5 on the bottom of the page. Other than THAT, and in any case try to avoid all three and use better assertions, as Eyal Eini (Ayende) from RavenDB wrote here: http://ayende.com/blog/4118/assert-true-is-the-tool-of-last-resort – pashute May 14 '15 at 12:52
15
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.

ASh
- 34,632
- 9
- 60
- 82

Anders Gustafsson
- 15,837
- 8
- 56
- 114