These requirements and the initial state of the code are extracted from the original GitHub repository
Parallel change is a technique used in refactoring to make a series of incremental changes to a codebase without breaking the existing code.
It involves three steps:
- Expand: Add new functionality to the codebase. It can be a class, method, variable... Try to create new code instead of modifying existing implementations, also is a good idea to make new tests for this expanded code even if duplicates previous test behaviors.
- Migrate: Move the existing code to the new functionality.
- Contract: Remove the old code.
The kata contains two files:
field
: the public interface of the code needs to stay as is, but the internal behavior of the class will change by adding a field class that will allow theShoppingCart
class to manage more than one item.method
: we want to introduce a new method in theAuthenticationService
and deprecate the existing one without breaking the code in the process.
During the refactoring, we need to focus on:
- Tests must be always green.
- Use IDE refactor tools when possible.
Note
The final state of the code after making both refactors are under two tags: one for the field scenario and the other for the method scenario.
The main objective of the kata is to gain a deeper understanding of the parallel change technique and improve the ability to refactor legacy code.
Important
We don't look for the code to be ultra-refactored creating new abstractions, design patterns, etc. Remember, we want to practice the parallel change process.
The project can be configured either by using pip
or pipenv
. Both ways will be explained.
Using pip
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate # Linux / Mac .venv\Scripts\activate # Windows
- Install the dependencies:
pip install -r requirements.txt
Using pipenv
-
Install pipenv:
pip install pipenv
-
Create a virtual environment with desire python version
pipenv --python 3.11
By default it will create the virtual environment outside the project. To create it inside the project, use the following command:
PIPENV_VENV_IN_PROJECT=1 pipenv --python 3.11
-
Install the dependencies:
pipenv install
To run the tests, execute one of the following commands:
pytest
or
pipenv run test