Skip to content

Commit f5abf11

Browse files
nateboschcopybara-github
authored andcommitted
Add a best practice sentence about data models
It should always be possible to use real instances for data only classes. Specifically mention data models in the best practices section as not needing mocks. PiperOrigin-RevId: 560634157
1 parent 70aabfc commit f5abf11

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,14 @@ throwOnMissingStub(cat);
433433

434434
Testing with real objects is preferred over testing with mocks - if you can
435435
construct a real instance for your tests, you should! If there are no calls to
436-
[`verify`] in your test, it is a strong signal that you may not need mocks at all,
437-
though it's also OK to use a `Mock` like a stub. When it's not possible to use
438-
the real object, a tested implementation of a fake is the next best thing - it's
439-
more likely to behave similarly to the real class than responses stubbed out in
440-
tests. Finally an object which `extends Fake` using manually overridden methods
441-
is preferred over an object which `extends Mock` used as either a stub or a
442-
mock.
436+
[`verify`] in your test, it is a strong signal that you may not need mocks at
437+
all, though it's also OK to use a `Mock` like a stub. Data models never need to
438+
be mocked if they can be constructed with stubbed data. When it's not possible
439+
to use the real object, a tested implementation of a fake is the next best
440+
thing; it's more likely to behave similarly to the real class than responses
441+
stubbed out in tests. Finally an object which `extends Fake` using manually
442+
overridden methods is preferred over an object which `extends Mock` used as
443+
either a stub or a mock.
443444

444445
A class which `extends Mock` should _never_ stub out its own responses with
445446
`when` in its constructor or anywhere else. Stubbed responses should be defined

0 commit comments

Comments
 (0)