Integration Test Best Practice

雨燕双飞 提交于 2019-12-13 00:24:42

问题


When creating integration tests, what is the best approach to introduce data?

Should sql scripts be used to create the data in the setup of the test or would it be better to use the actual business objects to generate data which can then be used by the tests.

Any help would be greatly appreciated.


回答1:


When creating test data for automated test there are a few rules I try to stick to and I find these rules help me achieve reliable tests that have a lower maintenance overhead:

  1. Avoid making the output of one test the input of another test i.e. dont use test A to create the test data for test B
  2. Avoid using objects under test to create test data i.e. if your testing module A dont use module A to create test data for any test
  3. Create test data in a way that's repeatable reliably at low cost e.g use SQL scripts to setup data
  4. When deciding how test data is to be created also consider how the test data will be removed so that your tests can be ran from a clean base state

In my environment I create test data using SQL at either the test fixture or test set-up point and then I clean out the test data using SQL at either the test fixture or test tear-down point.



来源:https://stackoverflow.com/questions/7433627/integration-test-best-practice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!