问题
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