Skip to content

Assert で生じた例外をラッピングして message パラメータを添付したい #16

Description

@in-async

カスタムアサートを書く際、現状だと 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); }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions