如何利用结构BDD CRUD测试 [英] How to Structure CRUD Tests using BDD

查看:227
本文介绍了如何利用结构BDD CRUD测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在一个有点困惑试图找出的的构造我的CRUD的测试方式。在我的应用程序的用户创建几种类型的'任务'的能力。我目前正在实施看起来是这样的:

I'm stuck at a bit of a quandary trying to figure out the best way of structuring my CRUD tests. Within my application users have the ability to create several types of 'tasks'. My currently implementation looks something like the following:

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,这当然崩溃和烧伤的运行时。

The reason I'm looking for help here is because I'm having trouble controlling execution order of the CRUD steps. I'm using Specflow and NUnit which executes the scenarios in alphabetical order rather than the order they appear in the feature file. Which results in this order C > D > R > U, which of course crashes and burns when run.

我尝试添加字符的场景名称的开头,造成这样的方案:第1阶段创建...,方案:第2阶段读......,等等。但正如我在做这个改变我忍不住在想如何砍十岁上下的感觉。我做了一些研究,但有大部分拿出一个更好的办法来控制执行顺序是空的。

I tried adding characters to the beginning of the scenario name, resulting in something like this "Scenario: Phase 1 Create...", "Scenario: Phase 2 Read...", and so on. But as I was making this change I could not help but thinking how 'hack-ish' it felt. I've done some research but have for the most part come up empty on a better way to control the execution order.

我确实有这些CRUD测试写的多;每种类型'任务'的,我想知道这将是更好的尝试和凝聚整个CRUD堆栈成一个单一的情况下,所以我不担心执行顺序或是否有更好的方法来控制执行?

I do have multiple of these CRUD tests to write; one for each type of 'task' and I'm wondering would it be better to try and condense the entire CRUD stack into a single scenario so I don't have to worry about execution order or is there a better way to control the execution?

推荐答案

一些内部的辩论中,我决定,这是徒劳的尝试和减少我已经写入的BDD语法试验后:

After some internal debate I decided that it was futile to try and reduce the tests I had already written into the BDD grammar of:

    [scenario name]
    [pre-condition]
    [action]
    [observation] 

和我结束了同是这样的:

And what I ended up with was something like this:

    [scenario name]
    [pre-condition]
    [action]
    [observation] 

    [pre-condition]
    [action]
    [observation] 

    ...
    [end]

下面是它看起来像原来的code。

Here's what it looks like with the original code.

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

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

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

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

我敢肯定有些人会用我的做法不以为然,因为它打破了BDD语法,但你应该知道这个执行完美的罚款,同时保持所有的单个方案的precision以及可读性。

I'm sure some will disagree with my approach since it breaks the BDD grammar, but you should know this executes perfectly fine while maintaining all the precision of the individual scenarios as well as readability.

这篇关于如何利用结构BDD CRUD测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆