This project demonstrates the principles of Test-Driven Development (TDD) in Python by implementing a simple use cases. It showcases how TDD can be applied to ensure code correctness while maintaining flexibility and robustness, using pytest for unit testing.
TDD is a software development practice where tests are written before the actual implementation. The typical TDD cycle involves:
- Write a test: Define a test that describes the desired functionality.
- Run the test: The test will fail initially, as the code isn't implemented yet.
- Write the code: Implement the smallest amount of code to pass the test.
- Refactor: Clean up the code while ensuring the test still passes.
- Repeat: Continue the cycle, building out the application.
TDD provides several benefits:
- Faster feedback on code quality.
- Improved design and modular code.
- Better documentation since tests clarify the expected behavior.
-
Clone the repository:
git clone https://github.com/drLacheheb/pyTDD.git cd pyTDD -
Install dependencies:
pip install -r requirements.txt
To run the tests using pytest, execute the following command:
pytestThis will automatically discover and run all tests in the tests/ directory. Pytest will show you a summary of the test results in the terminal.
- Early Bug Detection: Writing tests first allows issues to be identified and fixed early in the development process.
- Modular Design: TDD ensures that components are small, independent, and testable.
- Easy Maintenance: Each feature or bug fix is supported by tests, making it easy to extend or modify the project.