These instructions where extracted from Emily Bache repository. The link to the original repository can be found in the link bellow.
This kata is part of the Racing Kart Kata series, which is a set of exercises to practice TDD and SOLID principles.
There are several variants of this exercise in this repo. They all present slightly different challenges. You can expect to learn more about test design, SOLID principles and testability by working on them.
As a first step, try to get some kind of test in place before you change the class at all. If the tests are hard to write, is that because of the problems with SOLID principles?
When you have some kind of test to lean on, refactor the code and make it testable. Take care when refactoring not to alter the functionality, or change interfaces which other client code may rely on. Add more tests to cover the functionality of the particular class you've been asked to get under test.
Write the unit tests for the UnicodeFileToHtmlTextConverter class. This class is designed to reformat a plain text file for display in a browser.
Bonus: identify which of the SOLID principles this code violates.
Write the unit tests for the HtmlPagesConverter class. This class is designed to reformat a plain text file for display in a browser, one page at a time.
Write unit tests that expose the bugs. Bugs are marked with a comment in the code. You should preserve the original interface to the class.
The objective of the kata is to identify the SOLID principle that is not being followed and refactor the code to make it testable and maintainable.
We will learn how to work with legacy code that is difficult to test and learn how to refactor step by step. We can use Mocks, Stubs or none at all to test the code.
The project can be configured with poetry
and pyenv
.
-
Install python version with pyenv:
pyenv install 3.12.0
-
Install poetry:
pip install poetry
-
Create a virtual environment and install dependencies:
poetry install poetry install --dev
By default, it will create the virtual environment outside the project. To create it inside, use the following command:
poetry config virtualenvs.in-project true poetry install
-
Activate the virtual environment:
poetry shell
You can activate it manually running
source .venv/bin/activate
on Unix systems orsource .venv/Scripts/activate
on Windows.
To run the tests, execute one of the following commands:
pytest
or
poetry run pytest
- The Single Responsibility principle was not being followed. The class was responsible for reading a file and converting it to HTML, it had more than one reason to change.
- We've learned how to use Approval Tests to be able to refactor the code in safe steps without being completely sure of the behavior of the class.
- We've used Mocks to test the behavior of the class decoupled from the file system once we've refactored