Design Reusable Steps Specflow-这种方法是否正确

Design Reusable Steps Specflow-Is this approach correct

我们是 Specflow 的新手并试图在我们公司实施它,我们开发了一些功能作为 Smoke/Regression 测试的一部分并且目前 executing.We 正在遵循描述的方法 - 我们观察到的是重新使用步骤 - 这些步骤必须分解到其最 component/unit 特征,如下所示 -

Scenario: Search Cash book by Id
    Given Site browser launched
    Given Login is successful with "******" and "********"
    Given Set the service to "*******"
    Given Search a specific account "ABCDEFG" to match "Account"
    When A specific account is selected "ABCDEFG"
    When I search cash book with these data "CSX"
    Then the result should display records with transaction Amount "34"

我们观察到的是,如果您的步骤未按上述描述,则它们在其他功能中的可重用性非常有限。这种方法是正确的还是需要针对功能而非可重用性采取措施?

示例说明与您在上面尝试实现的关键字驱动测试不同。真正的 BDD 方法应该是这样的:

Feature: Viewing transaction amounts in certain cashbooks
As a customer
In order to know if I am paid
I want to see the amount next to a transaction

Background:
Given the following transaction:
    | Name      | Account   | CashBook | Transaction | Amount |
    | CustomerA | ABCDEFG   | CSX      | GlipGlob    | 1234   |

Scenario: A Cash book can be searched by ID
    Given I am logged in as CustomerA
    And I have selected the account "ABCDEFG"
    And I have selected the cash book "CSX"
    Then there should be a transaction with amount "1234"

后台检查是否存在and/or设置数据。如何完成对于功能(实现细节)并不重要。这可以通过直接数据库查询、网络服务或通过 GUI(不推荐)来完成。

场景 运行 也没有实现上下文:如果您 运行 作为网络服务器、通过浏览器或作为 Windows [=36] 并不重要=] 应用程序。因此,特征中不应出现 "checking checkboxes" 或 "filling editboxes" 和 "clicking links" 等信息。 除非您正在测试特定的页面布局。

在您的测试设计开始时,这会使您的步骤在低级别上的可重用性不高,因此您必须在胶水代码中创建可重用的步骤。对于 Selenium en webtesting,您可以使用 page object pattern 来实现。

最后,您将拥有一个更灵活的框架。当对象上的checkbox变成radiobutton或者只是一个link时,你只需要改变页面对象中的一个方法,而不是改变100个特性文件。
如果管理层决定他们想要一个 iPhone 应用程序,您可以重用所有测试,只需为您的粘合代码创建一个不同的界面。
当开发人员因为需要与其他源互连而将 REST API 交给应用程序时,您只需更改粘合代码即可重用相同的功能文件。

所以,是的,如果未在步骤中定义对象,则在低级别上步骤的可重用性不是很好,但在较长的过程中会给您带来巨大的优势 运行。当您想在可读步骤定义中使用低级步骤时,SpecFlow 可能不适合您。