Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
in-async opened this issue Apr 6, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@in-async
Copy link
Owner

in-async commented Apr 6, 2020

カスタムアサートを書く際、現状だと 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); }
@in-async in-async added the enhancement New feature or request label Apr 6, 2020
@in-async in-async self-assigned this Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant