カスタムアサートを書く際、現状だと message も都度書かなくてはならない。
TestAA
.Act(() => new { Id = 1, Name = "Foo" })
.Assert(ret => {
Assert.AreEqual(1, ret.Id, "No.1");
Assert.AreEqual("Bar", ret.Name, "No.1");
}, message: "No.1");
めんどくさいので、次のように書いても message がテスト結果に出力されるようにしたい。
TestAA
.Act(() => new { Id = 1, Name = "Foo" })
.Assert(ret => {
Assert.AreEqual(1, ret.Id);
Assert.AreEqual("Bar", ret.Name);
}, message: "No.1");
具体的には、Assert() 内で例外を catch し、新しい TestAssertFailedException のインスタンスでラッピングしつつ message も載せるのが良さそう。
try {
exception(Exception);
if (Exception == null) {
@return(Return);
}
}
catch (Exception ex) { throw new TestAssertFailedException(message, ex); }
カスタムアサートを書く際、現状だと message も都度書かなくてはならない。
めんどくさいので、次のように書いても message がテスト結果に出力されるようにしたい。
具体的には、Assert() 内で例外を catch し、新しい
TestAssertFailedExceptionのインスタンスでラッピングしつつ message も載せるのが良さそう。