SpecFlow を使用した動作駆動型開発に慣れてきた後、次のように、同じ機能に対して複数のシナリオを用意することに疑問を抱いていました。
登録機能
Feature: Register a new user
In order to use the system,
one must register with the system
so that one gets authorized and may login
Scenario: Register a new user using valid credentials
Given I am on the registration page
When I have entered my desired username "UserName" and password "password"
And I have confirmed my password "password"
And I click the register button
Then I shall get confirmation that I am now a registered user
私のシナリオが少し太りすぎた可能性があるという事実に加えて、次のような登録プロセス内の他のシナリオを検証することも管理する必要があります。
- 入力したユーザー名が短すぎます
- 入力パスワードが短すぎます
- 入力パスワードに数字が含まれていません
- 入力パスワードが確認パスワードと一致しません
ほんの数例を挙げると。SpecFlow 機能ファイルを使用したタグについて読んだことがあるので、おそらく次のようにすることができます。
@shorterPasswordProvided
Scenario: Register a user using a password that is too short
Given I am on the registration page
When I have entered my desired user name
And I have provided a password that is too short "allo"
And I click the Register button
Then I shall get an error message which mentions about the password minimum length
@noCredentialsAtAll
Scenario: Register a user using no credentials at all
Given I am on the registration page
When I click on the Register button with no credentials entered
Then I shall get an error message that says I have to fill all required fields in
次に、 を使用する[BeforeScenario("myTag")]
とうまくいくはずです。
フックを使用すると、特定のルールに従ってテストのサブセットを実行できます。したがって、When
メソッドは事前定義されたコンテキスト、つまり、実行されることを意図したフックを使用して実行でき、それはBeforeScenario
or the like 属性によって言及されます。
私は正しく理解しましたか、それともここで霧の中にいますか?
押しすぎですか?
何か不足していますか?
すべての「パスワードが短すぎる」、「資格情報が提供されていない」は、さまざまな使用シナリオと見なされますか、それとも、単体テスト自体のように、コード内の別の場所にしか収まらないものですか?
つまり、これらのシナリオはすべて Register 機能に属しているため、同じ Register.feature SpecFlow 機能ファイルで定義する必要がありますよね?