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.
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`