Comments (6)
Could you explain in more detail what spy!
would do? I'm unfamiliar with this Java library.
from mockall.
Would this guide be of help? https://www.baeldung.com/mockito-spy
from mockall.
So it wraps a real object, but records all of its calls for later inspection? I'm sure there would be s lot of hard cases. What about static methods? Generic methods?
from mockall.
So it wraps a real object, but records all of its calls for later inspection? I'm sure there would be s lot of hard cases. What about static methods? Generic methods?
It is almost the same as a mock, but it has a real object inside, and yes, it records all the info for later inspection. As for the static methods, there are two ways:
- Code generation, where the static methods are also mocked the same way as an ordinary method.
- An error is thrown.
Both of these are utilised in different Java frameworks. For example, the Spring framework doesn't care about the types at all: if it sees that an object can be changed fully without the code generation, it does just that; if it sees that the object is impossible to replace without the code generation, it utilises the same interface of the needed object to generate the code which does the required job. This is the mechanism for the bean injection: by an interface of implementation. Various unit testing frameworks also do one thing or another, so it depends.
The generic types are flattened, the same as when the compiler flattens it for a single symbol name. The generics are always parametrised, so there must be a parametrised mock, there can't be a non-parametrised mock.
As for this crate, I suggest we have a more versatile method where we also generate the code in case it is required.
from mockall.
What do you mean "without the code generation"? How would any of this work without code generation?
from mockall.
What do you mean "without the code generation"? How would any of this work without code generation?
Without generating a completely new code for the same type, which does exactly what the original one does, with or without decorating. I meant the code generation in Java terms, not in Rust terms. Of course, we always generate code in Rust here, but in Java, for the mocks, we can implement the interface and exploit the difference in behaviour this way, while for a concrete type (or any other type that can't be mocked any other way), we can only regenerate the code and either wrap the real object inside and delegate the calls to it, or copy-paste the code from the original implementation using the language reflection mechanisms to inline it into the just-generated type. So, please, don't be confused with the "code generation" from Java, just ignore it then.
from mockall.
Related Issues (20)
- Anonymous lifetime in trait method HOT 6
- Mocking an internal struct with external dependency HOT 7
- Capturing arguments from returning HOT 2
- Struggling to mock trait objects and make assertions on functions that take ownership of mock trait object HOT 4
- Mock trait with methods that return iterators HOT 8
- Mock Trait that is a composition of two other traits HOT 2
- Struct with different traits that has identically named methods HOT 1
- Can't apply `automock` to traits with default method implementions marked `#[inline]` HOT 1
- Remove ...
- Problem with mocking a trait which uses &Self HOT 1
- Mockall Double of struct in external crate HOT 2
- mocking struct & mockall_double::double not working as expected HOT 10
- Mocking with tokio::sync::Mutex, confused for std::sync::Mutex HOT 4
- Feature request: support for `const generics` in `mock!` and `automock` HOT 4
- Mocking Default Trait Method Implementations HOT 4
- How to bypass a mock for a particular test and call the original function HOT 3
- automock fails for method taking Option<&u32> HOT 5
- MSRV 1.77.0 TODO
- Mocking a function taking an FnMut closure incompatible with concretize HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockall.