Refactoring
Refactoring is the process for restructuring an existing body of code, altering its internal structure without changing its external behavior.
In Twist, refactoring helps you in evolving and maintaining your tests suite.
Reasons to refactor:
- Rename a business workflow step so that it reflects its business intent better.
- Add or remove parameters to business workflows.
Rephrase refactoring
Rephrase refactoring allows you to rename business workflows and change the parameters that it accepts.
Consider the business 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:
- Check destination account is credited to make it more readable.
- Check destination account "2345" is credited "1000" so that you can reuse the workflow step in other scenarios as it now accepts parameters.
Push to Implementation
Push to Implementations allows you to achieve abstraction at the underlying implementation level.
For example,
Create Order
- Create an order "O" as price "23" quantity "50"
- Submit order "O"
You may wish to refactor the two workflow steps as one logical step and combine them as one, at the code level:
Create Order
- Submit an order "O" as price "23" quantity "50"
Inferring parameters in extracted code
- If you specify a new parameter, Twist introduces a new parameter in your extracted concept
-
If you specify a parameter that is present in any of the extracted
workflow steps, Twist parametrizes all occurrences
of that parameter in the underlying code.
For example,
Create Order
- Create an order "O" as price "23" quantity "50"
- Submit order "O"
- Submit an order "O" as price "23" quantity "50" then the underlying code is refactored as follows:
public void submitAnOrderAsPriceQuantity(String string1, int price, int quantity) {
createAnOrderAsPriceQuantity(string1, price, quantity);
submitOrder(string1);
}
Note: When you push a set of steps within a scenario to implementation, Twist will automatically replace all scenarios where these set of steps occur with the new step. Read more about Push To Implementation Propagation

