Convenience factory for stubs
See original GitHub issueA stub(Class)
factory method on the Mockito
class would be a convenient way to create stub-only objects:
List stub = stub(List.class);
Such a factory method improves the clarity of test code by succinctly communicating the test author’s intent for the test-double.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Java 9 Convenience Factory Methods for Collections - Baeldung
A quick and practical guide to creating collections and maps using Java 9 factory methods.
Read more >Static factory methods in Swift - Swift by Sundell
Test stubs. It's not only in our main app code that we have to perform lots of setup, we also often have to...
Read more >Java Convenience Factory Methods for Collections
Java Convenience Factory Methods for Collections · Allows to create a list, set, and map of values in just one line. Creating immutable...
Read more >express-test-stubs - npm
A helper factory function that produces test fakes for the need of unit-testing Express endpoints. This module makes use of stampit library -...
Read more >Reference — Factory Boy stable documentation
The 'stub' strategy is an exception in the factory_boy world: it doesn't return an instance of the model class, and actually doesn't require...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a follow up, can the issue be re-opened and have the discussion flow continue?
Please reconsider this issue. As this blog post from Martin Fowler points out, it’s very important to make a clear distinction between mocks and stubs. Even though at a first glance the difference between them is not that significant -
stubs are mocks but you can't verify them
- from a testing theory point of view the difference is significantly huge. One enables behavioural testing (i.e mocks) and the other enables state testing. Two different styles of testing with deep implications.Having a clean
stub(...)
API will actually encourage people to think more careful about what kind of testing they want to do and what should be actually used.I’ve seen numerous people, including myself, using the
mock(...)
API as a stub - no verify assertions done. Believe it or not, most people ignore theMockSettings
parameter, or they don’t look deep enough to what that interface provides.I would like to argue that since mockito cared to provide a convenience factory for spies (Martin Fowler’s blog post considers them as
stubs that also record some information based on how they were called
) the stub method should also be provided for better readability, encourage correctness code, ease of use and finding.