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

docs: mock, fake stub guidelines #76

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all 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
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Test Exception Raised](#test-exception-raised)
- [Test Fixture](#test-fixture)
- [Test Structure](#test-structure)
- [Test Mocks, Stubs and Fakes](#test-mocks-stubs-and-fakes)
- [Type Hints](#type-hints)

The [Charm development best practices](https://juju.is/docs/sdk/styleguide) are
Expand Down Expand Up @@ -465,6 +466,20 @@ compared to the main branch as a result of the PR.

This ensures a high coverage minimum and no coverage regression.

## Test Mocks, Stubs and Fakes

It is a good standard to differentiate between test mocks, stubs and fakes in
unit tests in order to avoid having problems while refactoring or updating code.
For example, when changing a behavior of a module/class, testing fakes must also
be modified to reflect the changes in the behavior. A proper naming can help
during the refactor.

Mock: implements the interface of an object under test, used to verify
interactions between classes.
Stub: implements predefined answers to calls, used to verify different code
paths.
Fake: a lightweight implementation of an object. e.g. in memory db.
Comment on lines +477 to +481
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should link to an article or something that goes into more depth here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I'm also thinking about updating this with an example but the documentation might become lengthy so perhaps an article might be better :D


## Type Hints

Python is a dynamic programming language that does not require type
Expand Down