Eyes, JAPAN Blog > D言語でBDD

D言語でBDD

mima

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

あけましておめでとうございます。

さっそくですが、D言語でBDDフレームワークを作ってみました。
dspecs
1ファイル構成のライブラリなので、適当にダウンロードしてインポートして使ってください。


こんな感じでBDDできます。

unittest
{
    static struct Hoge
    {
        bool match = true;
        string str = "abc";
    }

    static struct Piyo
    {
        int i;
        this(int i)
        {
            this.i = i * i;
        }
    }

    "abc".should |
    {
        "start with a".by |
        {
            assert("abc".startsWith("a"));
        };

        "end with c".by |
        {
            assert("abc".endsWith("c"));
        };
    };

    "initial instance of Hoge".should |
    {
        Hoge hoge;

        "match".by |
        {
            assert(hoge.match);
        };

        "have member str which is abc".by |
        {
            assert(hoge.str == "abc");
        };
    };

    "Piyo(10).i".は | 
    {
        "100である".べき |
        {
            assert(Piyo(10).i == 100);
        };
        "101でない".べき |
        {
            assert(Piyo(10).i != 101);
        };
    };
}

日本語でも大丈夫です。


このライブラリの詳しい解説などは、Codelogyで行う予定です。

担当:美馬(UFCSが素晴らしい)

  • このエントリーをはてなブックマークに追加

Comments are closed.