From 89e61ed68e91c7510181b56a0d55bd88d975899d Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Tue, 17 Dec 2024 16:24:12 +0100 Subject: [PATCH] Proofread testing.md (#433) Rename file --- CONTRIBUTING.md | 2 +- docs/{test_and_coverage.md => testing.md} | 21 +++++++-------------- mkdocs.yml | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) rename docs/{test_and_coverage.md => testing.md} (79%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44c0d5fc..d4724d14 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -127,7 +127,7 @@ Check out [duniterpy#169](https://git.duniter.org/clients/python/duniterpy/-/iss [{: style="height:150px;width:150px"}](https://pytest.org) </center> -We are using [Pytest](https://pytest.org) as a tests framework. For more information on how Silkaj implements them check the [project test documentation](/test_and_coverage/). +We are using [Pytest](https://pytest.org) as a tests framework. For more information on how Silkaj implements them check the [testing documentation](/testing/). Tests are stored into `unit` and `integration` folders depending on their types, then using a similar tree as the source code. diff --git a/docs/test_and_coverage.md b/docs/testing.md similarity index 79% rename from docs/test_and_coverage.md rename to docs/testing.md index 83321a35..c880c77c 100644 --- a/docs/test_and_coverage.md +++ b/docs/testing.md @@ -2,10 +2,8 @@ ### Install tests dependencies -Using pipenv: - ``` -pipenv install --dev +poetry install ``` ### Runing tests: @@ -13,29 +11,24 @@ pipenv install --dev Simply run: ``` -pytest +poetry run pytest ``` To have a coverage report: ``` -pytest --cov silkaj --cov-report html:cov_html +poetry run pytest --cov silkaj --cov-report html --cov-report xml --cov-report term ``` -Where: - -- `--cov silkaj` option generates coverage data on the silkaj package -- `--cov-report html:cov_html` generates a browsable report of coverage in cov_html dir. You can omit this if you just want coverage data to be generated - See [pytest documentation](https://docs.pytest.org/en/latest/usage.html) for more information ### Writing tests -There should be 3 kinds of test: +There should be three kinds of test: -- end to end test: uses the real data and the real blockchain. Obviously don't presume the data value as it can change. These test are written in tests/test_end_to_end.py. +- end to end test: uses the real data and the real blockchain. Obviously don't presume the data value as it can change. These test are written in `tests/integration/test_end_to_end.py`. - integration test: mock some of the input and/or output classes and shouldn't use the actual blockchain, you should use this when mocking a class (used by your code) is too complicated. -- unit test: for functions that don't need mock or mock can me done easily (you should prefer this to integration tests). Are written in tests/test_unit\_*package*.py +- unit test: for functions that don't need mock or mock can me done easily (you should prefer this to integration tests). Are written in `tests/unit/test_*package*.py` You should try to write an end to end test first, then if your coverage too bad add some unit tests. If it's still too bad, write an integration test. @@ -45,7 +38,7 @@ A better strategy (TDD) is to write first the End to end test. When it fails, be Test an Exception is raised: https://docs.pytest.org/en/latest/assert.html#assertions-about-expected-exceptions -Test a function with several values: You can use pytest.mark.parametrize as done in tests/test_unit_tx.py +Test a function with several values: You can use `@pytest.mark.parametrize` as done in `tests/unit/money/test_transfer.py` To mock a user input: diff --git a/mkdocs.yml b/mkdocs.yml index 34dc283f..51560392 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -59,7 +59,7 @@ nav: - Poetry installation: install_poetry.md - Docker installation: docker.md - Documentation: documentation.md - - test_and_coverage.md + - Testing: testing.md - Coverage report: coverage.md extra: -- GitLab