Functional Test Refactoring: Move

Move test steps into the sections that execute before/after test cases

Zhimin Zhan
Geek Culture
Published in
4 min readApr 2, 2021

--

This is one of the 6 Functional Test Refactorings:

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
# ...
end
it "One-way trip" do
login("agileway", "testwise")

--

--

Zhimin Zhan
Geek Culture

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.