database - 许多小的 dbunit 数据集还是一个大的数据集?

标签 database testing junit dbunit

在我看来,每当调整模式时,将测试数据分布在多个小数据集上都会造成维护难题。有人发现创建一个更大的测试数据集有问题吗?我所说的“更大”仍然只是总共几百条记录。

最佳答案

我不会使用独特的大型数据集(如果不需要,您希望避免任何开销)并遵循 DbUnit 的 Best Practices建议:

Use multiple small datasets

Most of your tests do not require the entire database to be re-initialized. So, instead of putting your entire database data in one large dataset, try to break it into many smaller chunks.

These chunks could roughly corresponding to logical units, or components. This reduces the overhead caused by initializing your database for each test. This also facilitates team development since many developers working on different components can modify datasets independently.

For integrated testing, you can still use the CompositeDataSet class to logically combine multiple datasets into a large one at run time.

来自 Unitils 人员的更多反馈:

Automatic test database maintenance

When writing database tests, keep in mind following guidelines:

  • Use small sets of test data, containing as few data as possible. In your data files, only specify columns that are used in join columns or the where clause of the tested query.
  • Make data sets test class specific. Don't reuse data sets between different test classes, for example do not use 1 big domain data set for all your test classes. Doing so will make it very difficult to make changes to your test data for a test without braking anything for another test. You are writing a unit test and such a test should be independent of other tests.
  • Don't use too many data sets. The more data sets you use, the more maintenance is needed. Try to reuse the testclass data set for all tests in that testclass. Only use method data sets if it makes your tests more understandable and clear.
  • Limit the use of expected result data sets. If you do use them, only include the tables and columns that are important for the test and leave out the rest.
  • Use a database schema per developer. This allows developers to insert test data and run tests without interfering with each other.
  • Disable all foreign key and not null constraints on the test databases. This way, the data files need to contain no more data than absolutely necessary

过去,使用具有足够数据的小型数据集对我们来说效果很好。当然,如果您调整数据库,则需要进行一些维护,但这对于某些组织来说是可以管理的。

关于database - 许多小的 dbunit 数据集还是一个大的数据集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2970083/

相关文章:

python - 解析复杂的查询参数

ios - SQLite 数据库不可写

php - 如何测试使用字符串正文发送的 Laravel 邮件,而不是使用 Mailable

unit-testing - 当组件调用的服务抛出 Angular 2 异常时,测试组件是否正常运行

database - 为什么 RDBMS 不支持列的数组类型?

c# - 如何更改数据库 - Entity Framework (mysql 数据库)使用的模式?

haskell - 如何导入模块进行测试?

java - JUnit ArrayList 为空

java - 在 h2 数据库中编写查询以转换日期格式

java - junit 流图 Java 8