diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44c0d5fcecbfe6b83d9d4126b9ca8cad0d22f86b..d4724d14566fdefd78d0cb454fbc7e73692ab8b1 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 83321a357b0cb1f99899dc96b6d06be07bdcebc0..c880c77c90c7fcd146199064658a7fe2bc430b4c 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 34dc283f695af33075211911c4f14abb4ffdc6fc..51560392ab026258b5f59b9be70d90f9ed601d0a 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: