我陷入了一个进退两难的境地,试图找出答案best构建我的 CRUD 测试的方式。在我的应用程序中,用户可以创建多种类型的“任务”。我当前的实现如下所示:
Scenario: Create Task-Type A
Given I am on a user's profile page
And Have access to create tasks
When I create a new task with a unique title and description
Then The confirmation prompt should display
Scenario: Read the Task-Type A
Given A new task was created
When I search the text on the page for the unique title
Then I should find the task
And All the details of the task should match what was created
Scenario: Update the Task-Type A
Given A task exists
And I have opened the edit dialog
When I make the following changes:
| title | description | date | save |
| "" | "" | "" | yes |
Then all the saved changes should match the task details
Scenario: Delete the Take-Type A
Given A task exist
When I select the option to delete
And I confirm deletion process
Then The Task should no longer exist in the list
我在这里寻求帮助的原因是因为我无法控制 CRUD 步骤的执行顺序。我使用 Specflow 和 NUnit,它们按字母顺序而不是它们在功能文件中出现的顺序执行场景。这会导致这个顺序 C > D > R > U,这当然会在运行时崩溃并烧毁。
我尝试在场景名称的开头添加字符,结果是“场景:第 1 阶段创建...”、“场景:第 2 阶段读取...”等。但当我做出这个改变时,我忍不住想这感觉是多么“黑客”。我已经做了一些研究,但在很大程度上没有找到更好的方法来控制执行顺序。
我确实有多个这样的 CRUD 测试要编写;每种类型的“任务”都有一个,我想知道是否最好尝试将整个 CRUD 堆栈压缩为一个场景,这样我就不必担心执行顺序,或者是否有更好的方法来控制执行?
依赖场景的执行顺序是一种反模式,应该避免。出于同样的原因,测试运行程序通常不提供任何机制来控制执行顺序。这也违背了可执行规范的概念:场景本身应该是可理解的(并且可执行的)。
Source: Specflow - “场景”之间的状态 https://stackoverflow.com/questions/7158810/specflow-state-between-scenarios
因此,我建议使用一种场景,或者,如果您想要单独的场景,只需使它们独立于执行顺序即可。
例如,对于删除场景,您应该在此场景中执行 CRU 前提条件,然后执行带有验证的删除步骤。
对于最佳实践(恕我直言) - 请参阅 Kent Beck 文章:https://www.facebook.com/notes/kent-beck/decompose-run-on-tests/555371804495688 https://www.facebook.com/notes/kent-beck/decompose-run-on-tests/555371804495688
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)