Skip to content
Snippets Groups Projects
Commit 89e61ed6 authored by Moul's avatar Moul
Browse files

Proofread testing.md (#433)

Rename file
parent 12df42e9
No related branches found
No related tags found
1 merge request!271Set up new website structure with MkDocs (#433)
......@@ -127,7 +127,7 @@ Check out [duniterpy#169](https://git.duniter.org/clients/python/duniterpy/-/iss
[![Pytest logo](images/pytest_logo.svg){: 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.
......
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment