Skip to content

Exercise 011: Refactor Active Side Effects in Then Step

🔗 Related Smell: 011 - Active Side Effects in Then Step

Purpose

  • Learn to identify the Active Side Effects in Then Step smell.
  • Recognize the misuse when changing an application state in a Thenstep.

Your Task

The step implementation consists two Then steps that changes the data of the system under tests. Find the Then steps with the smell and move the state change to a fitting When step.

Solution

Hint A
  • You are looking for a Then steps that deal with the verification of the second customer.
Hint B
  • The relevant step are Then the second customer creation should fail and Then the second customer can be found.
  • Look at the implementation of the code in the step definition.
  • Which code is concerning the active side effect?
Hint C
  • The relevant step are Then the second customer creation should fail and Then the second customer can be found.
  • Both implementations are creating a new customer object!
  • Where does this code belong to?
Step by Step Walkthrough
  • The relevant step are Then the second customer creation should fail and Then the second customer can be found.
  • Both implementations are creating a new customer object!
  • Remove the creation of the customer object.
  • Create the customer in the step When the second customer is created instead.
  • Implement it similar as in When the customer is created.
  • Should we merge the expressions of When the customer is created and When the second customer is created, or keep it?