単純比較
- 期待される答え (
expected
) と、実際の実行結果 (actual
) を与えて比較する。
- 2つが同じなら成功(メソッド名の通りになっていれば成功)
Assert.Equal("期待される答え", "実際の実行結果");
Assert.Equal(2, MyMath.Add(1, 1));
メソッド |
説明 |
Assert.Equal<T>(T expected, T actual) |
|
Assert.Equal(decimal expected, decimal actual, int precision) |
同じなら成功。10進数で小数点以下 precision 桁になるように丸め込んで比較する。 |
Assert.Equal(double expected, double actual, int precision) |
同じなら成功。10進数で小数点以下 precision 桁になるように丸め込んで比較する。 |
Assert.NotEqual<T>(T expected, T actual) |
|
Assert.NotEqual(decimal expected, decimal actual, int precision) |
同じなら成功。10進数で小数点以下 precision 桁になるように丸め込んで比較する。 |
Assert.NotEqual(double expected, double actual, int precision) |
同じなら成功。10進数で小数点以下 precision 桁になるように丸め込んで比較する。 |
Assert.Equal<T>(T expected, T actual, IEqualityComparer<T> comparer) |
|
Assert.NotEqual<T>(T expected, T actual, IEqualityComparer<T> comparer) |
|
Boolean 系
True
メソッド |
説明 |
Assert.True(bool condition) |
condition が true なら成功 |
Assert.True(bool? condition) |
condition が true なら成功 |
Assert.True(bool condition, string userMessage) |
condition が true なら成功。userMessage はメッセージ |
Assert.True(bool? condition, string userMessage) |
condition が true なら成功。userMessage はメッセージ |
False
メソッド |
説明 |
Assert.False(bool condition) |
condition が false なら成功 |
Assert.False(bool? condition) |
condition が false なら成功 |
Assert.False(bool condition, string userMessage) |
condition が false なら成功。userMessage はメッセージ |
Assert.False(bool? condition, string userMessage) |
condition が false なら成功。userMessage はメッセージ |
文字列系
比較系
メソッド |
説明 |
Assert.Equal(string expected, string actual) |
actual が expected と同じなら成功 |
Assert.Equal(string expected, string actual, bool ignoreCase = false, bool ignoreLineEndingDifferences = false, bool ignoreWhiteSpaceDifferences = false) |
actual が expected と同じなら成功
ignoreCase : true なら大文字と区別しない
ignoreLineEndingDifferences : true なら改行コードの違いを区別しない
ignoreWhiteSpaceDifferences : true ならホワイトスペースの違いを区別しない(全角スペースはダメ?) |
包含系
メソッド |
説明 |
Assert.EndsWith(string expectedEndString, string actualString) |
|
Assert.EndsWith(string expectedEndString, string actualString, StringComparison comparisonType) |
|
Assert.StartsWith(string expectedStartString, string actualString) |
|
Assert.StartsWith(string expectedStartString, string actualString, StringComparison comparisonType) |
|
Assert.Contains(string expectedSubstring, string actualString) |
|
Assert.Contains(string expectedSubstring, string actualString, StringComparison comparisonType) |
|
Assert.DoesNotContain(string expectedSubstring, string actualString) |
|
Assert.DoesNotContain(string expectedSubstring, string actualString, StringComparison comparisonType) |
|
正規表現系
メソッド |
説明 |
Assert.DoesNotMatch(string expectedRegexPattern, string actualString) |
|
Assert.DoesNotMatch(Regex expectedRegex, string actualString) |
|
Assert.Matches(Regex expectedRegex, string actualString) |
|
Assert.Matches(string expectedRegexPattern, string actualString) |
|
Null
メソッド |
説明 |
Assert.Null(object @object) |
@object の参照が null なら成功 |
Assert.NotNull(object @object) |
@object が null なら成功 |
型
public static T IsAssignableFrom(object @object);
public static void IsAssignableFrom(Type expectedType, object @object);
public static void IsNotType(object @object);
public static void IsNotType(Type expectedType, object @object);
public static T IsType(object @object);
public static void IsType(Type expectedType, object @object);
例外
public static T Throws(Action testCode) where T : Exception;
public static T Throws(Func testCode) where T : Exception;
public static T Throws(string paramName, Action testCode) where T : ArgumentException;
public static T Throws(string paramName, Func testCode) where T : ArgumentException;
public static Exception Throws(Type exceptionType, Action testCode);
public static Exception Throws(Type exceptionType, Func testCode);
public static T ThrowsAny(Action testCode) where T : Exception;
public static T ThrowsAny(Func testCode) where T : Exception;
public static Task ThrowsAnyAsync(Func testCode) where T : Exception;
public static Task ThrowsAsync(Func testCode) where T : Exception;
public static Task ThrowsAsync(string paramName, Func testCode) where T : ArgumentException;
public static Task ThrowsAsync(Type exceptionType, Func testCode);
public static void All(IEnumerable collection, Action action);
public static void Collection(IEnumerable collection, params Action[] elementInspectors);
public static void Contains(IEnumerable collection, Predicate filter);
public static void Contains(T expected, IEnumerable collection);
public static void Contains(T expected, IEnumerable collection, IEqualityComparer comparer);
public static void DoesNotContain(IEnumerable collection, Predicate filter);
public static void DoesNotContain(T expected, IEnumerable collection);
public static void DoesNotContain(T expected, IEnumerable collection, IEqualityComparer comparer);
public static void Empty(IEnumerable collection);
public static void Equal(IEnumerable expected, IEnumerable actual);
public static void Equal(IEnumerable expected, IEnumerable actual, IEqualityComparer comparer);
public static void InRange(T actual, T low, T high) where T : IComparable;
public static void InRange(T actual, T low, T high, IComparer comparer);
public static void NotEmpty(IEnumerable collection);
public static void NotEqual(IEnumerable expected, IEnumerable actual);
public static void NotEqual(IEnumerable expected, IEnumerable actual, IEqualityComparer comparer);
public static void NotInRange(T actual, T low, T high) where T : IComparable;
public static void NotInRange(T actual, T low, T high, IComparer comparer);
public static void NotSame(object expected, object actual);
public static void NotStrictEqual(T expected, T actual);
public static void ProperSubset(ISet expectedSuperset, ISet actual);
public static void ProperSuperset(ISet expectedSubset, ISet actual);
public static void PropertyChanged(INotifyPropertyChanged @object, string propertyName, Action testCode);
protected static Exception RecordException(Func testCode);
protected static Task RecordExceptionAsync(Func testCode);
public static void Same(object expected, object actual);
public static T Single(IEnumerable collection);
public static object Single(IEnumerable collection);
public static T Single(IEnumerable collection, Predicate predicate);
public static void Single(IEnumerable collection, object expected);
public static void StrictEqual(T expected, T actual);
public static void Subset(ISet expectedSuperset, ISet actual);
public static void Superset(ISet expectedSubset, ISet actual);