Functional Test Refactoring: Move
Move test steps into the sections that execute before/after test cases
This is one of the 6 Functional Test Refactorings:
- Extract Function
- Move Function to Helper
- Move
- Extract Page Function
- Introduce Page Object
- Rename
The structure of this article is the same as “Extract Function” refactoring. The test project that helps you do refactoring exercises quickly:
> cd my-working-dir
> git clone https://github.com/testwisely/agiletravel-ui-tests
The test project is at my-working-dir/agiletravel-ui-tests/pre-refactoring
.
Motivation
You have the same set of beginning or ending test steps in multiple test cases.
Long and similar test cases are harder to maintain. By grouping test cases and utilize shared sections, it is possible to make test cases concise and more distinguishable.
Sample Test (before)
The test script file in the sample project: spec/flight_spec.rb
before(:all) do
# ...
endit "One-way trip" do
login("agileway", "testwise")…