NUnit StringAssertを試してみる
NUnit 2.2.7にてStringAssertを試してみました。
これも2.2.3のバージョンから存在するアサーションです。
あんまり使ってなかったので反省...
[TestFixture] public class StringAssertTest { [Test] public void 指定文字列が含まれているかな() { StringAssert.Contains("Hello", "Hello World"); StringAssert.Contains("世界", "こんにちは世界"); } [Test] [ExpectedException(typeof(AssertionException))] public void 指定文字列が含まれてい無い場合例外を返す() { StringAssert.Contains("Hello", "Goodbye World"); } [Test] public void 空文字列が含まれているか調べてみると通っちゃいますね() { // 通常はこういう書き方はしないけど StringAssert.Contains(string.Empty, "Goodbye World"); } [Test] [ExpectedException(typeof(AssertionException))] public void 空文字列に何か含まれているか調べると当然例外を返す() { StringAssert.Contains("Goodbye World", string.Empty); } [Test] [ExpectedException(typeof(AssertionException))] public void 日本語の指定文字列が含まれてい無い場合例外を返す() { StringAssert.Contains("世界", "こんにちは地球"); } [Test] public void 開始文字列を確認してみよう() { StringAssert.StartsWith("Hello", "Hello NAgile"); StringAssert.StartsWith("こんにち", "こんにちはNAgile"); } [Test] [ExpectedException(typeof(AssertionException))] public void 指定文字列で開始されていない無い場合例外を返す() { StringAssert.StartsWith("Hello", "Goodbye Waterfall"); } [Test] [ExpectedException(typeof(AssertionException))] public void 日本語の指定文字列で開始されていない無い場合例外を返す() { StringAssert.StartsWith("こんばんみ", "こんにちは地球"); } [Test] public void 開始文字列に空文字列を指定してみると通る() { // 通常はこういう書き方はしないけど StringAssert.StartsWith(string.Empty, "Hello NAgile"); } [Test] public void 終了文字列を確認してみよう() { StringAssert.EndsWith("NAgile", "Hello NAgile"); StringAssert.EndsWith("アジャイル", "こんにちはエヌアジャイル"); } [Test] [ExpectedException(typeof(AssertionException))] public void 指定文字列で終わっていない場合例外を返す() { StringAssert.EndsWith("Baby", "Goodbye Waterfall"); } [Test] [ExpectedException(typeof(AssertionException))] public void 日本語の指定文字列で終わっていない場合例外を返す() { StringAssert.EndsWith("世界", "こんにちは地球"); } [Test] public void 終了文字列に空文字列を指定してみると通ります() { // 通常はこういう書き方はしないけど StringAssert.EndsWith(string.Empty, "Hello NAgile"); } [Test] public void 大文字小文字の区別なく文字列を比較したい() { StringAssert.AreEqualIgnoringCase("hello world", "Hello World"); } [Test] public void AreEqualIgnoringCaseメソッドで全く同じ文字列を比較してみる() { StringAssert.AreEqualIgnoringCase("Hello World", "Hello World"); } [Test] public void AreEqualIgnoringCaseメソッドで空文字列同士を比較してみる() { StringAssert.AreEqualIgnoringCase(string.Empty, string.Empty); } [Test] [ExpectedException(typeof(AssertionException))] public void 全角カナとひらがなを比較してみるとやっぱり例外発生() { StringAssert.AreEqualIgnoringCase("エヌアジャイル", "えぬあじゃいる"); } }