Как автоматизировать функциональные / интеграционные тесты и откаты базы данных

Используя ProcessExplorer и нависающий над процессом Java покажет командную строку.

7
задан Community 23 May 2017 в 10:34
поделиться

2 ответа

Changes made in a transaction are only visible inside said transaction. Also wrapping the test in a transaction scope (if possible) would make the test behave differently than the real thing in a very critical aspect (transactions).

It is much better to use a database image that you restore before every test suite. This way after the suite completes and the verification is done, you drop the test database. The next run, during the suite setup, the database is re-created from the saved image in a pristine state ready for testing. Even better would be to have a script that deploys the database from scratch and run that script during suite setup.

Btw is not feasible to restore to a pristine state before every test. More generically is not feasible to have lengthy individual test setup and cleanup steps. As you add more tests the time spent restoring the database to test-ready condition between tests will become just unmanageable. Suites with hundreds of tests are quite common and full test runs of tens of thousands of tests would mean hours and hours spent just restoring database for test. Design your individual test so that they can be run independently, ie. test N has to produce valid results even if test N-1 failed.

Another thing to consider is failure investigation, you want your failed test to leave the database in a state that can be investigated for meaningful info and you want subsequent tests to be able to run and produce valid results. Sometimes these requirements will contradict each other, but you must take them into consideration and design your test around them.

7
ответ дан 6 December 2019 в 15:24
поделиться

Если объем данных, необходимых для восстановления базы данных до заведомо исправного состояния, недопустим для сценариев удаления / создания, и вы запускаете тесты в SQL 2005 для разработчиков или Enterprise, вы можете изучите создание снимка базы данных хорошего состояния и возврат к нему перед каждым тестом. Это значительно быстрее, чем полное восстановление, хотя может занять слишком много времени, если у вас есть сотни тестов.

7
ответ дан 6 December 2019 в 15:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: