1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-15 14:27:50 +02:00

Explain that mocking.md has AOSP recommendations (#1545)

A follow-up to #1532.
This commit is contained in:
Martin Geisler 2023-12-01 16:10:27 +01:00 committed by GitHub
parent d0bab8302c
commit f837afa034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -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.
@ -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>