Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing best practices #1381

Closed
wants to merge 9 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/integrations/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ def test_function():

If the function raises a ValueError with proper error message, the test will pass.

## Content Testing Guidelines

dorschw marked this conversation as resolved.
Show resolved Hide resolved
* 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.
dorschw marked this conversation as resolved.
Show resolved Hide resolved
* 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 rely on the time of running.
dorschw marked this conversation as resolved.
Show resolved Hide resolved
* 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_).

dorschw marked this conversation as resolved.
Show resolved Hide resolved
## Troubleshooting Tips

* The `demisto-sdk lint` by default prints out minimal output. If for some reason it is failing and not clear, run the
Expand Down
Loading