From d06160dd961762b90331653abe81dfc40abc6149 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Fri, 22 Mar 2024 12:25:10 +0900 Subject: [PATCH 1/2] mock fake stub differentiation guideline --- CONTRIBUTING.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 035fe34..0adf3d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -465,6 +466,19 @@ 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. + ## Type Hints Python is a dynamic programming language that does not require type From 163a333a0bcf4501581239e09985a154502b9717 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Fri, 22 Mar 2024 12:25:40 +0900 Subject: [PATCH 2/2] formatting --- CONTRIBUTING.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0adf3d3..e8c1595 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -474,9 +474,10 @@ 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. +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. ## Type Hints