我是 BDD、Specflow 和 WatiN 的新手。我想使用这些工具来自动化我的 ASP.NET MVC 应用程序的验收测试。
我已经弄清楚了如何基本使用这些工具,并且我成功构建了我的第一个验收测试:登录网站。
这是这个测试的小黄瓜:
Feature: Log on to the web
As a normal user
I want to log on to the web site
Scenario: Log on
Given I am not logged in
And I have entered my name in the username textbox
And I have entered my password in the password textbox
When I click on the login button
Then I should be logged and redirected to home
现在,我想写一堆其他的测试,它们都需要对用户进行身份验证。例如:
Feature: List the products
As an authenticated user
I want to list all the products
Scenario: Get Products
Given I am authenticated
And I am on the products page
When I click the GetProducts button
Then I should get a list of products
让我烦恼的是,为了使这个测试独立于其他测试,我必须编写代码才能再次登录网站。这是要走的路吗?我怀疑。
我想知道是否有最佳实践可以用于测试这样的场景。我应该保持浏览器打开并让测试在同一个浏览器上按特定顺序运行吗?还是应该将 MVC 应用程序置于特定状态?