VS2005環境でのNAgile - NUnit 2.2.7のアサーション (^o^)
今日はNUnit 2.2.7のアサーションに対して一つ一つユニットテストを書いてみた。同時に足らないスニペットも追加しながら。
NUnit 2.2からはアサーションの種類も増えているので学習も兼ねて。作成したテストフィクスチャは以下。
- EqualityAssertsTest
- IdentityAssertsTest
- ComparisonAssertsTest
- TypeAssertsTest
- ConditionTestsTest
- UtilityMethodsTest
- StringAssertTest
例えばTypeAssertsTestのコードはこのような感じ。
using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; namespace NUnitStudy.Tests { [TestFixture] public class TypeAssertsTest { [Test] public void インスタンスの同型チェックが成功すべき() { string actual = "Test"; Assert.IsInstanceOfType(typeof(string), actual); } [Test] [ExpectedException(typeof(AssertionException))] public void インスタンスの同型チェックが失敗すべき() { string actual = "Test"; Assert.IsInstanceOfType(typeof(int), actual); } [Test] public void インスタンスの異型チェックが成功すべき() { string actual = "Test"; Assert.IsNotInstanceOfType(typeof(int), actual); } [Test] [ExpectedException(typeof(AssertionException))] public void インスタンスの異型チェックが失敗すべき() { string actual = "Test"; Assert.IsNotInstanceOfType(typeof(string), actual); } [Test] public void 型へのインスタンス代入可チェックが成功すべき() { object actual = new object(); Assert.IsAssignableFrom(typeof(string), actual); } [Test] [ExpectedException(typeof(AssertionException))] public void 型へのインスタンス代入可チェックが失敗すべき() { object actual = "Test"; Assert.IsAssignableFrom(typeof(object), actual); } [Test] public void 型へのインスタンス代入不可チェックが成功すべき() { object actual = "Test"; Assert.IsNotAssignableFrom(typeof(object), actual); } [Test] [ExpectedException(typeof(AssertionException))] public void 型へのインスタンス代入不可チェックが失敗すべき() { object actual = new object(); Assert.IsNotAssignableFrom(typeof(string), actual); } } }