Skip to content

Commit 5d5af1f

Browse files
committed
update Readme
1 parent 378b7db commit 5d5af1f

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

README.md

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,77 @@
22

33
# Unit Tests Practice
44

5-
#### This repository explores some possibilities of automated tests (unittest and pytest) to verify the import and conversion of simple JSON quizzes. It was also my first steps in using Markdown documentation.
5+
#### This repo explores a wide range of testing techniques — mocking, fixtures, test-class inheritance, a simulated HTTP server and continuous integration — using simple multiple-choice quizzes stored as JSON. It also compares the automated tests through unittest and pytest, and was also my first steps with Markdown documentation.
6+
7+
## Overview
8+
9+
| Program | Role |
10+
|---|---|
11+
| `questionnaire.py` | Loads a JSON quiz, displays it in the terminal and counts the score. |
12+
| `questionnaire_import.py` | Downloads quizzes from an online source and converts them to the project [json format](./questionnaire.md#expected-json-schema). |
13+
| `questionnaire_unit_test.py` | Automated test suite for `questionnaire.py`. |
14+
15+
The test suite is the heart of the project: it stacks several techniques on a single use case.
616

717
---
818

9-
## questionnaire_import.py
10-
>python3 ./questionnaire_import.py
19+
## Installation
20+
21+
```bash
22+
python -m venv venv
23+
source venv/bin/activate # Linux / macOS (venv\Scripts\activate on Windows)
24+
pip install -r requirements.txt # to use questionnaire.py only
25+
pip install -r requirements-dev.txt # to use questionnaire_unit_tests.py
26+
```
1127

12-
Loads some quizzes from a sample list in the program and converts them into a specific [json format](./questionnaire.md#expected-json-schema) before to save them
13-
into the [json_questionnaires](./json_questionnaires) folder
28+
## questionnaire_import.py : Import and convert online quizzes into json_questionnaires
29+
>python3 ./questionnaire_import.py
1430
1531
More info : [questionnaire_import.md](./questionnaire_import.md)
1632

1733
---
1834

19-
## questionnaire.py
20-
>python3 ./questionnaire.py <questionnaire.json>
21-
22-
Displays the quiz in argument and counts the number of good answers
35+
## questionnaire.py : Displays the quiz in argument and counts the number of good answers
36+
>python3 ./questionnaire.py ./json_questionnaires/<questionnaire.json>
2337
2438
More info : [questionnaire.md](./questionnaire.md)
2539

2640
---
2741

28-
## questionnaire_unit_tests.py
29-
>python3 ./questionnaire_unit_tests.py
30-
31-
Uses the `unittest` automated framework but not only to test questionnaire.py
42+
## questionnaire_unit_tests.py : Run the tests with `unittest` or `pytest`
43+
# use ./json_test_files folder to check 25 intentionally broken quizzes targeting error cases
44+
>python3 -m unittest questionnaire_unit_test.py ./json_test_files/<questionnaire.json>
45+
>pytest -v questionnaire_unit_test.py -s ./json_test_files/<questionnaire.json>
3246
3347
More info : [questionnaire_unit_test.md](./questionnaire_unit_test.md)
3448

35-
Uses the files:
36-
- json_00_empty.json
37-
- json_00_without_extension
38-
- json_01_good_format.json
39-
- json_01_another_good_format.json
40-
- pytest.ini
4149

42-
and files into [json_test_files](./json_test_files) folder
50+
## Testing highlights
51+
52+
- **Test-class inheritance** to reuse base cases by changing a single parameter.
53+
- **Mocking** with `unittest.mock.patch` to simulate `sys.argv`.
54+
- **Threaded local HTTP server** (`ThreadingMixIn` + `SimpleHTTPRequestHandler`) to test
55+
remote loading without relying on the internet.
56+
- **`setUp`/`tearDown` (unittest) vs `@pytest.fixture` (pytest)** for the same need, to
57+
compare both frameworks directly.
58+
59+
60+
## Continuous integration
61+
62+
GitHub Actions runs on every push and pull request to `master`: dependency install
63+
(Python 3.10), `flake8` lint, then the test suite under both `unittest` and `pytest`.
4364

4465
---
4566

4667
## [Requirements](./requirements.txt)
68+
- Python 3.10+
4769
- jsonschema==4.17.0
4870
- parameterized==0.8.1
4971
- requests==2.28.1
5072
- validators==0.20.0
5173

74+
## [Requirements-dev](./requirements-dev.txt)
75+
- pytest==7.2.0
76+
- flake8==6.0.0
77+
78+

0 commit comments

Comments
 (0)