mirror of https://github.com/zulip/zulip.git
docs: Add additional reason why mocking is useful.
This commit is contained in:
parent
c953759486
commit
211fbdf59b
|
@ -119,12 +119,19 @@ Additionally, you can observe any calls made to your mocked object.
|
||||||
|
|
||||||
#### Why is mocking useful?
|
#### Why is mocking useful?
|
||||||
|
|
||||||
When writing tests, it often occurs that you make calls to functions taking complex arguments. Creating a real
|
When writing tests, it often occurs that you make calls to functions
|
||||||
instance of such an argument would require the use of various different libraries, a lot of boilerplate code, etc.
|
taking complex arguments. Creating a real instance of such an argument
|
||||||
Another scenario is that the tested code accesses files or objects that don't exist at testing time.
|
would require the use of various different libraries, a lot of
|
||||||
|
boilerplate code, etc. Another scenario is that the tested code
|
||||||
|
accesses files or objects that don't exist at testing time. Finally,
|
||||||
|
it is good practice to keep tests independent from others. Mocks help
|
||||||
|
you to isolate test cases by simulating objects and methods irrelevant
|
||||||
|
to a test's goal.
|
||||||
|
|
||||||
In such cases, you can "mock out" the function calls / objects and replace them with fake instances that only implement a
|
In all of these cases, you can "mock out" the function calls / objects
|
||||||
limited interface. On top of that, these fake instances can be easily analyzed.
|
and replace them with fake instances that only implement a limited
|
||||||
|
interface. On top of that, these fake instances can be easily
|
||||||
|
analyzed.
|
||||||
|
|
||||||
Say you have a method `foo(input_str)`:
|
Say you have a method `foo(input_str)`:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue