Skip to content

Commit

Permalink
Explain that mocking.md has AOSP recommendations (#1545)
Browse files Browse the repository at this point in the history
A follow-up to #1532.
  • Loading branch information
mgeisler authored Dec 1, 2023
1 parent d0bab83 commit f837afa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/testing/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minutes: 5

# Mocking

If you want to do mocking, we recommend [Mockall]. You need to refactor your
For mocking, [Mockall] is a widely used library. You need to refactor your
code to use traits, which you can then quickly mock:

```rust,ignore
Expand All @@ -15,7 +15,13 @@ code to use traits, which you can then quickly mock:

<details>

- Note that *mocking is controversial*: mocks allow you to completely isolate a
- The advice here is for Android (AOSP) where Mockall is the recommended mocking library.
There are other [mocking libraries available on crates.io](https://crates.io/keywords/mock),
in particular in the area of mocking HTTP services. The other mocking libraries work
in a similar fashion as Mockall, meaning that they make it easy to get a mock implementation
of a given trait.

- Note that mocking is somewhat *controversial*: mocks allow you to completely isolate a
test from its dependencies. The immediate result is faster and more stable
test execution. On the other hand, the mocks can be configured wrongly and
return output different from what the real dependencies would do.
Expand Down Expand Up @@ -53,6 +59,4 @@ code to use traits, which you can then quickly mock:
called to `n` --- the mock will automatically panic when dropped if this isn't
satisfied.
- Mockall is available for use in AOSP.
</details>

0 comments on commit f837afa

Please sign in to comment.