1

次のようなスペックフローテストがいくつかあります。

Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email

Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email

2つのシナリオだけでなく、10の非常によく似たシナリオがあり、すべてステップのタイプがあるので、「シナリオの概要」を使用したいと思います。残念ながら、私は自分のステップを書き直すための読みやすい方法を思い付くのに本当に苦労しています。

現在、私はこれを思いついたが、不格好に見える:

Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email

Examples:
| !notes   | personDoes/NotExist | personShould/NotGetEmail |
| Exists   | does not            | should                   |
| No Exist | does                | should not               |

私もこれを考えました、そしてそれはよりきれいですが、それはほとんど意味を伝えません

Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')

Examples:
| !notes   | personExist | sendEmail |
| Exists   | false       | true      |
| No Exist | does        | false     |

「する」、「しない」、「すべき」、「すべきではない」、「持っている」、「持っていない」などの概念をパラメーター化するためのより良い方法を持っている人はいますか?この時点で、読みやすいので、すべてを別のシナリオとして残すことを考えています。

4

2 に答える 2

1

これが私が過去にやったことです:

Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1  | John       | Galt      | x     |
| 2  | Howard     | Roark     | y     |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1           | John       | Galt      |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1           | John       | Galt      | x     |
| 2           | Howard     | Roark     | y     |
And the following accounts should have been sent an email
| External Id | Email |
| 2           | y     |

SpecFlow で table.CreateSet() および table.CreateSet() ヘルパー メソッドを使用して、テーブルを偽の外部システム リポジトリおよびデータベース内のアカウント テーブルのデータにすばやく変換できます。

次に、table.CompareToSet(accountRepository.GetAccounts() を使用して、"Then" 句のテーブルをデータベースのレコードと比較できます。

すばらしいことに、作成したすべての手順は複数の状況で再利用できます。テーブルのデータを変更するだけで、SpecFlow がテストを作成します。

それが役立つことを願っています!

于 2012-01-12T20:41:56.153 に答える
0

たぶん、それらを2つのシナリオに分割する必要があります

Scenario Outline: User exists in the repository
Given a person
| Field | Value   |
| First | <first> |
| Last  | <last>  |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email

Examples:
| first   | last   |
| Bob     | Smith  |
| Sarah   | Jane   |

そして、反対の別のシナリオ。これにより、シナリオの意味が非常に明確になります。一般的な手順が一般的に表現されている場合は、それらを再利用できます。私もユーザーのアプローチから来るようにしています

于 2012-02-21T22:25:31.180 に答える