diff --git a/docs/integrations/unit-testing.md b/docs/integrations/unit-testing.md index 426836eee..4f9457cd9 100644 --- a/docs/integrations/unit-testing.md +++ b/docs/integrations/unit-testing.md @@ -225,6 +225,17 @@ def test_function(): If the function raises a ValueError with proper error message, the test will pass. +## Content Testing Guidelines + +* When testing a command, mock all external requests (e.g. mock `Client` methods), run the command on given inputs, and compare the output to a hardcoded value. +* When using demistomock, mock the `demisto` object directly using `mocker`, don't rely on the defaults. +* Prefer comparing whole outputs (e.g. comparing the output to a `CommandResult` object), to make sure the code behavior is preserved even when others add features and fix issues. +* Use the `@freezegun.freeze_time` decorator on the testing method when the output may vary in different time, date or timezone (e.g. daylight-saving time) in run time. +* Methods that handle errors or exceptions should have multiple tests - one for the _happy path_ (normal functionality, without errors), and one testing method for each error handled (a.k.a _sad path/s_). +* Make sure to sanitize or remove any sensitive data (passwords, tokens, email addresses, personal information, etc.) from unit tests and test data. +* Using `pytest.parametrize` is preferred over loops in a unit test. Use `pytest.param` to give each case an `id` (Learn more [here](https://docs.pytest.org/en/7.1.x/example/parametrize.html)) +* When a few lines are repeated in multiple tests as setup, consider using fixtures instead. Learn more about Pytest fixtures [here](https://docs.pytest.org/en/6.2.x/fixture.html). + ## Troubleshooting Tips * The `demisto-sdk lint` by default prints out minimal output. If for some reason it is failing and not clear, run the