1

DAO をテストするときは、次のルールに従います。

  • インメモリ データベースを使用する
  • テストごとにデータベース データをリセットする

これは、データベースからの選択に適しています。選択に必要なデータを使用してデータベースをセットアップし、DAO を呼び出して、返されたオブジェクトが正しい値であることを確認します。

しかし、挿入、更新、および削除をテストすると、見苦しくなります。データベースに正しいデータが挿入/更新/削除されたことを確認するために、カスタム select ステートメントを作成する必要があります。したがって、テストの作成が終了したら、テストをもう一度テストすることもできます。

ウェブ上の一部の人々は、文字通りすべてをモックすることを提案していますが、それは実際には何もテストしていません.

では、DAO をテストするにはどうすればよいでしょうか。

4

2 に答える 2

1

You don't really have to test DAO, provided they are slim enough (as they should be) and don't contain business logic. You're going to inadvertently test them at some point while writing some system/integration tests for something else.

Depending on what you're using (ORM framework?) you might be able to stub/mock stuff, but it's rarely worth it.

As for using connection strings in NUnit (so to manipulate the DB from your test project), I see nothing wrong with that in general, it's more common than you'd think.

于 2016-07-06T09:09:54.847 に答える