Integration Test Best Practice

2019-08-14 22:23发布

问题:

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.