Refactoring

Refactoring is technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

You may want to modify existing workflow steps to reflect changing business needs in due course. For example, you may want to:

  1. Rename a workflow step so that it reflects its business intent better.
  2. Add or remove parameters to workflows.
Refactoring allows you to perform these operations without breaking existing tests. If a workflow step is used in more than one scenario, refactoring the workflow step in one scenario affects all the scenarios that use the workflow.

Refactoring, thus, is a powerful concept that helps you maintain your tests suites better.

Rephrase refactoring

Rephrase refactoring allows you to rename workflows and change the parameters that it accepts. Consider the Workflow below:

Transfer
  • transfer "1000" from account "1234" to "2345"
  • destination account is credited

You may want to rephrase the workflow step destination account is credited to one of the following:
  1. Check destination account is credited to make it more readable.
  2. Check destination account "2345" is credited "1000" so that you can reuse the workflow step in other scenarios as it now accepts parameters.

Extract Concept

"Extract Concept" makes it possible to merge two or more related statements to create a more meaningful abstraction. For example,
Login
  • Open the application
  • Login using username 'username' and password 'password'
You can refactor the two workflow steps as one logical step:
Login
  • Login as user 'username' using password 'password'