データベースのテストに抵抗するで🤜🤛


データベースのテストに抵抗するで🤜🤛

なんか色々書こうと思ったけど時間がなかったで…

先人の知見

とりあえず、アプリケーションではなくデータベース自体のテストが必要になったときに調べたことを少し書く。

どうするべきか?という観点

データベーステストにXUnit系の方式を導入するときの問題点

要はオブジェクト指向型のソースコードベースのテストじゃなくて、SQLベースでテストしようぜという話

The problem with xUnit-like database testing tools is that they require too much boilerplate code.
I could never get database developers to really use them when no one was looking over their shoulders.
Writing tests was simply seen as too much overhead. All the buzz about object-relational mismatch over the last few years was mostly about relational models getting in the way of object development. This is effectively the other side of the problem, with object tools getting in the way of relational testing.

xUnit系のデータベース試験ツールの問題点は、たくさんのボイラープレートコードを書かなければいけないということだ。わたしは、職場でDBエンジニアの肩越しにモニターを見たときにこれらのツールを実際に使われるところを見たことがない。テストを書くことは単純にオーバーヘッド(※その処理の本質ではないこと)になりすぎる。ここ最近でネットでバズっていた、オブジェクトと関係テーブルのミスマッチの問題というのは、関係テーブルというモデルがオブジェクト指向の開発のやり方の妨げになるということである。これは問題のもう一つの側面であり、逆に言えばオブジェクト指向的なツールは関係テーブルの試験の妨げになる。

FIT testing framework, on the other hand, does not suffer from that mismatch.
FIT is an acceptance testing framework developed by Ward Cunningam,
which is customer oriented and has nothing to do with database unit testing whatsoever.
But FIT tests are described as tables, which is much more like the relational model than Java code.
FIT also has a nice Web-wiki front-end called FitNesse,
which allows database developers to write tests on their own without help from Java or .NET developers.
DbFit utilises the power of these two tools to make database tests easy.

FIT testing frameworkは対照的に、このミスマッチで苦しむことはない。FITはワード・カニンガムによって開発された受入テスト用のフレームワークである。これは顧客指向でデータベースの単体テストとは何の関係もない。しかし、FITのテストはテーブルとして記述される、これはJavaのコードというよりはもっと関係テーブルというものに近い。FITはFitNesseというWikiスタイルのフロントエンドをもっている。これはDBエンジニアがJavaや.NETの開発者の助けを借りずに自分自身でテストを書くことが可能になるということだ。DbFitツールはこれらの2つのツールを使ってデータベースの試験を簡単にする。

具体的にやっていく

こんな感じでかけるらしい

!|insert|source   |
|col1   |col2|col3|
|val1   |val2|val3|

|execute procedure|some_procedure|
|param1           |param2        |
|val1             |val2          |

|query   |select * from target|
|col1    |col2    |col3       |
|exp_val1|exp_val2|exp_val3   |