Assertions Library
Assertions Library
Search and explore all available TUnit assertions
51 assertions found
IsEqualTo
EqualityAsserts the value equals the expected value
await Assert.That(actual).IsEqualTo(expected)await Assert.That(5).IsEqualTo(5)IsNotEqualTo
EqualityAsserts the value does not equal the expected value
await Assert.That(actual).IsNotEqualTo(expected)await Assert.That(5).IsNotEqualTo(3)IsGreaterThan
ComparisonAsserts the value is greater than expected
await Assert.That(actual).IsGreaterThan(expected)await Assert.That(10).IsGreaterThan(5)IsLessThan
ComparisonAsserts the value is less than expected
await Assert.That(actual).IsLessThan(expected)await Assert.That(3).IsLessThan(10)IsGreaterThanOrEqualTo
ComparisonAsserts the value is greater than or equal to expected
await Assert.That(actual).IsGreaterThanOrEqualTo(expected)await Assert.That(5).IsGreaterThanOrEqualTo(5)IsLessThanOrEqualTo
ComparisonAsserts the value is less than or equal to expected
await Assert.That(actual).IsLessThanOrEqualTo(expected)await Assert.That(5).IsLessThanOrEqualTo(10)IsNull
NullAsserts the value is null
await Assert.That(actual).IsNull()await Assert.That(nullValue).IsNull()IsNotNull
NullAsserts the value is not null
await Assert.That(actual).IsNotNull()await Assert.That(value).IsNotNull()IsDefault
DefaultAsserts the value is the default value for its type
await Assert.That(actual).IsDefault()await Assert.That(0).IsDefault()IsNotDefault
DefaultAsserts the value is not the default value
await Assert.That(actual).IsNotDefault()await Assert.That(5).IsNotDefault()IsTrue
BooleanAsserts the value is true
await Assert.That(actual).IsTrue()await Assert.That(condition).IsTrue()IsFalse
BooleanAsserts the value is false
await Assert.That(actual).IsFalse()await Assert.That(!condition).IsFalse()Contains
StringAsserts the string contains the expected substring
await Assert.That(actual).Contains(substring)await Assert.That("hello world").Contains("world")DoesNotContain
StringAsserts the string does not contain the substring
await Assert.That(actual).DoesNotContain(substring)await Assert.That("hello").DoesNotContain("world")StartsWith
StringAsserts the string starts with the expected prefix
await Assert.That(actual).StartsWith(prefix)await Assert.That("hello world").StartsWith("hello")EndsWith
StringAsserts the string ends with the expected suffix
await Assert.That(actual).EndsWith(suffix)await Assert.That("hello world").EndsWith("world")IsEmpty
StringAsserts the string is empty
await Assert.That(actual).IsEmpty()await Assert.That("").IsEmpty()IsNotEmpty
StringAsserts the string is not empty
await Assert.That(actual).IsNotEmpty()await Assert.That("text").IsNotEmpty()HasLength
StringAsserts the string has the expected length
await Assert.That(actual).HasLength().EqualTo(length)await Assert.That("hello").HasLength().EqualTo(5)Contains (Collection)
CollectionsAsserts the collection contains the expected item
await Assert.That(collection).Contains(item)await Assert.That(list).Contains(5)DoesNotContain (Collection)
CollectionsAsserts the collection does not contain the item
await Assert.That(collection).DoesNotContain(item)await Assert.That(list).DoesNotContain(10)HasCount
CollectionsAsserts the collection has the expected count
await Assert.That(collection).HasCount().EqualTo(count)await Assert.That(list).HasCount().EqualTo(3)IsEmpty (Collection)
CollectionsAsserts the collection is empty
await Assert.That(collection).IsEmpty()await Assert.That(emptyList).IsEmpty()IsNotEmpty (Collection)
CollectionsAsserts the collection is not empty
await Assert.That(collection).IsNotEmpty()await Assert.That(list).IsNotEmpty()IsEquivalentTo
CollectionsAsserts collections have equivalent items (order-independent)
await Assert.That(collection).IsEquivalentTo(expected)await Assert.That(list).IsEquivalentTo([1,2,3])HasSingleItem
CollectionsAsserts the collection has exactly one item
await Assert.That(collection).HasSingleItem()await Assert.That(singleItemList).HasSingleItem()IsPositive
NumericAsserts the number is positive
await Assert.That(actual).IsPositive()await Assert.That(5).IsPositive()IsNegative
NumericAsserts the number is negative
await Assert.That(actual).IsNegative()await Assert.That(-5).IsNegative()IsZero
NumericAsserts the number is zero
await Assert.That(actual).IsZero()await Assert.That(0).IsZero()IsNotZero
NumericAsserts the number is not zero
await Assert.That(actual).IsNotZero()await Assert.That(5).IsNotZero()IsEven
NumericAsserts the number is even
await Assert.That(actual).IsEven()await Assert.That(4).IsEven()IsOdd
NumericAsserts the number is odd
await Assert.That(actual).IsOdd()await Assert.That(3).IsOdd()IsBetween
NumericAsserts the number is between min and max
await Assert.That(actual).IsBetween(min, max)await Assert.That(5).IsBetween(1, 10)Throws
ExceptionsAsserts the action throws an exception
await Assert.That(() => action()).Throws()await Assert.That(() => throw new Exception()).Throws()ThrowsExactly
ExceptionsAsserts the action throws exactly the specified exception type
await Assert.That(() => action()).ThrowsExactly<TException>()await Assert.That(() => throw new ArgumentException()).ThrowsExactly<ArgumentException>()ThrowsException
ExceptionsAsserts the action throws the specified exception type or derived
await Assert.That(() => action()).ThrowsException<TException>()await Assert.That(() => throw new InvalidOperationException()).ThrowsException<Exception>()ThrowsWithMessage
ExceptionsAsserts the exception has the expected message
await Assert.That(() => action()).Throws().WithMessage(message)await Assert.That(() => throw new Exception("error")).Throws().WithMessage("error")IsTypeOf
TypeAsserts the value is exactly the specified type
await Assert.That(actual).IsTypeOf<TType>()await Assert.That(obj).IsTypeOf<MyClass>()IsAssignableTo
TypeAsserts the value is assignable to the specified type
await Assert.That(actual).IsAssignableTo<TType>()await Assert.That(derived).IsAssignableTo<BaseClass>()IsAssignableFrom
TypeAsserts the type is assignable from the value
await Assert.That(actual).IsAssignableFrom<TType>()await Assert.That(baseInstance).IsAssignableFrom<DerivedClass>()IsAfter
DateTimeAsserts the date is after the expected date
await Assert.That(actual).IsAfter(expected)await Assert.That(DateTime.Now).IsAfter(yesterday)IsBefore
DateTimeAsserts the date is before the expected date
await Assert.That(actual).IsBefore(expected)await Assert.That(yesterday).IsBefore(DateTime.Now)IsOnOrAfter
DateTimeAsserts the date is on or after the expected date
await Assert.That(actual).IsOnOrAfter(expected)await Assert.That(DateTime.Now).IsOnOrAfter(today)IsOnOrBefore
DateTimeAsserts the date is on or before the expected date
await Assert.That(actual).IsOnOrBefore(expected)await Assert.That(today).IsOnOrBefore(DateTime.Now)ContainsKey
DictionaryAsserts the dictionary contains the specified key
await Assert.That(dict).ContainsKey(key)await Assert.That(dict).ContainsKey("key")DoesNotContainKey
DictionaryAsserts the dictionary does not contain the key
await Assert.That(dict).DoesNotContainKey(key)await Assert.That(dict).DoesNotContainKey("missing")ContainsValue
DictionaryAsserts the dictionary contains the specified value
await Assert.That(dict).ContainsValue(value)await Assert.That(dict).ContainsValue("value")IsCompleted
AsyncAsserts the task is completed
await Assert.That(task).IsCompleted()await Assert.That(Task.CompletedTask).IsCompleted()IsNotCompleted
AsyncAsserts the task is not completed
await Assert.That(task).IsNotCompleted()await Assert.That(runningTask).IsNotCompleted()IsFaulted
AsyncAsserts the task is faulted
await Assert.That(task).IsFaulted()await Assert.That(faultedTask).IsFaulted()IsCancelled
AsyncAsserts the task is cancelled
await Assert.That(task).IsCancelled()await Assert.That(cancelledTask).IsCancelled()