|
1 | | -# python-testing |
2 | | -python testing example |
| 1 | +# Python Testing with Unittest |
3 | 2 |
|
4 | | -# Doc Testing Python |
5 | | -https://docs.python.org/3/library/unittest.html |
| 3 | +This repository is designed to illustrate how to perform unit testing in Python using the `unittest` tool. The project is structured in evolutionary steps, represented in different Git branches: `step__1`, `step__2`, ..., up to `step__14`. Each branch shows a step toward the full implementation of tests, from the initial setup to the integration of tests and the generation of coverage reports. |
6 | 4 |
|
7 | | -# Run test |
8 | | -python3.12 -m unittest discover -v -s tests |
| 5 | +## Project Structure |
9 | 6 |
|
10 | | -# Run suites |
11 | | -PYTHONPATH=. python3.12 tests/suites.py |
| 7 | +- **Branches**: Each branch contains a specific phase of the unit testing development. You can follow the progress of the implementation step by step starting from `step__1` to `step__14`. |
| 8 | +- **Unit Tests**: The tests are organized within the `src_tests` folder. |
| 9 | +- **Test Coverage**: The **Coverage** tool is used to measure the test coverage and generate detailed reports. |
12 | 10 |
|
13 | | -# run tests |
14 | | -``` |
15 | | -python3.12 -m unittest discover -v -s tests |
16 | | -``` |
| 11 | +## Commands Used |
17 | 12 |
|
18 | | -# Coverage |
19 | | -``` |
20 | | -coverage run --source src -m unitest |
21 | | -coverage report |
22 | | -coverage html |
23 | | -``` |
| 13 | +Here are the main commands used in this project to run the tests and generate coverage reports: |
24 | 14 |
|
| 15 | +1. **Run unit tests**: |
| 16 | + ```bash |
| 17 | + python3.12 -m unittest discover -v -s src_tests |
| 18 | + ``` |
25 | 19 |
|
26 | | -# Bugs |
27 | | -```bash |
28 | | -# this comand not run if not change folder tests to other unique name |
29 | | -coverage run --source ./src_tests -m unittest |
| 20 | +2. **Run tests from a specific file:**: |
| 21 | + ```bash |
| 22 | + PYTHONPATH=. python3.12 src_tests/suites.py |
| 23 | + ``` |
| 24 | + |
| 25 | +3. **Generate coverage report:**: |
| 26 | + ```bash |
| 27 | + coverage run --source src -m unittest |
| 28 | + coverage report |
| 29 | + coverage html |
| 30 | + ``` |
| 31 | + |
| 32 | +4. **Run unit tests**: |
| 33 | + ```bash |
| 34 | + coverage run --source ./src_tests -m unittest |
| 35 | + ``` |
| 36 | +## Purpose |
| 37 | + |
| 38 | +The purpose of this project is to teach and demonstrate how to structure a testing project in Python, how to use `unittest` to test functions, and how to achieve full test coverage using the `coverage` tool. By following the different branches, developers can see how the project is structured and progresses, continually improving the tests and ensuring their quality. |
| 39 | + |
| 40 | +## Conclusion |
| 41 | + |
| 42 | +This project is a practical example of how to structure a testing project in Python, and how to use `unittest` to test functions. |
0 commit comments