依赖按顺序运行的自动化测试是否可以被视为不好的做法? [英] Can it be considered bad practice to rely on automated tests running in order?
问题描述
在我的验收测试套件中,我看到很多测试旨在按特定顺序(从上到下)运行,这在某些方面对测试特定流程很有意义,但我也听说这是不好的做法.任何人都可以阐明这里的优缺点吗?
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?
推荐答案
在大多数情况下,如果您依赖顺序,就会出现问题.最好解决这个问题,因为:
In majority situations if you rely on the order, there is something wrong. It's better to fix this because:
- 测试应该是独立的,以便能够单独运行它们(您应该只能运行 1 个测试).
- 测试运行工具通常不能保证顺序.即使今天是一个特定的序列,明天你可以向跑步者添加一些配置,顺序就会改变.
- 很难从测试报告中确定出了什么问题,因为您看到很多失败,而只有 1 个测试失败.
- 同样 - 从测试报告工具跟踪测试步骤并不容易,因为这些步骤被分配给不同的测试.
- 如果需要,您将无法并行运行它们(希望您不需要).
如果您想共享逻辑 - 创建可重用的类或方法(参见 这个).
If you want to share logic - create reusable classes or methods (see this).
PS:我将这些称为系统测试,而不是验收测试 - 您也可以在单元或组件级别编写验收测试.
PS: I'd call these System Tests, not Acceptance Tests - you can write acceptance tests on unit or component levels too.
这篇关于依赖按顺序运行的自动化测试是否可以被视为不好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!