You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-16 14:17:34 +02:00
Explain that mocking.md has AOSP recommendations (#1545)
A follow-up to #1532.
This commit is contained in:
@ -4,7 +4,7 @@ minutes: 5
|
|||||||
|
|
||||||
# Mocking
|
# 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:
|
code to use traits, which you can then quickly mock:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
@ -15,7 +15,13 @@ code to use traits, which you can then quickly mock:
|
|||||||
|
|
||||||
<details>
|
<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 from its dependencies. The immediate result is faster and more stable
|
||||||
test execution. On the other hand, the mocks can be configured wrongly and
|
test execution. On the other hand, the mocks can be configured wrongly and
|
||||||
return output different from what the real dependencies would do.
|
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
|
called to `n` --- the mock will automatically panic when dropped if this isn't
|
||||||
satisfied.
|
satisfied.
|
||||||
|
|
||||||
- Mockall is available for use in AOSP.
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
Reference in New Issue
Block a user