Can it be considered bad practice to rely on automated tests running in order?

烂漫一生 提交于 2019-12-13 17:36:43

问题


In my acceptance test suites specifically I see a lot of tests designed to run in a particular order (top to bottom) which in some ways makes sense for testing a particular flow, but I've also heard this is bad practice. Can anyone shed some light on the advantages and drawbacks here?


回答1:


In majority situations if you rely on the order, there is something wrong. It's better to fix this because:

  • Tests should be independent to be able to run them separately (you should be able to run just 1 test).
  • Test-running tools often don't guarantee the order. Even if today it's a particular sequence, tomorrow you could add some configuration to the runner and the order will change.
  • It's hard to determine what's wrong from the test reports since you see a lot of failures while there is only 1 test that failed.
  • Again - from the test report tools it's not going to be easy to track the steps of the tests because these steps are assigned to different tests.
  • You won't be able to run them in parallel if you'd need to (hopefully you don't).

If you want to share logic - create reusable classes or methods (see this).

PS: I'd call these System Tests, not Acceptance Tests - you can write acceptance tests on unit or component levels too.



来源:https://stackoverflow.com/questions/40349496/can-it-be-considered-bad-practice-to-rely-on-automated-tests-running-in-order

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