Comments (10)
What you posted looks correct. Perhaps the problem lies somewhere else? Are there any other imports?
from mockall.
maybe it's in the mod file?
What I have is:
src
----> main.rs
----> storage
--------> client.rs
---------> mod.rs
my mod.rs looks like:
pub mod client;
I already posted the entire code for client.rs. I have a lib.rs in the same directory as main.rs that has:
pub mod storage;
That's pretty much it..
from mockall.
When do you see the error? Is it when you do cargo build
or cargo test --bin
? What version of Mockall are you using?
from mockall.
I'm using the latest version 0.12.1
. I see it in cargo build, cargo test and vscode linter when i'm looking at the code.
from mockall.
But cargo test
does lots of things: unit tests, integration tests, and doc tests. It even checks the examples. That's why I asked specifically for cargo test --bin
. That will tell you if your project builds successfully in test mode.
from mockall.
just ran it with cargo test --bin:
error[E0432]: unresolved import `<project_name>::storage::client::MockHelloClient`
--> src/main.rs:38:5
|
38 | use < project_name>::storage::client:: HelloClient;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------
| | |
| | help: a similar name exists in the module: `HelloClient`
| no `MockHelloClient ` in `storage::client`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `project_name` (bin "project_name" test) due to 1 previous error
from mockall.
That tells you that your project fails to build in test mode. You also said that it fails during cargo build
. But that error message doesn't make sense for non-test mode. Are you sure that you get the same error during cargo build
?
from mockall.
sorry, that's my bad, cargo build
works fine.
from mockall.
Your problem is that your crate contains both a library and a binary. When you build the binary in test mode, the library is built in non-test mode, just like an external dependency. So you need to either:
- Eliminate the library and move everything into the binary
- Make mockall a full dependency, possibly feature-gated, and export the mocks always
- Define the mock structure using
mock!
in the binary, not#[automock]
in the library.
from mockall.
oh i see. thank you!
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 with tokio::sync::Mutex, confused for std::sync::Mutex HOT 4
- Feature request: create a `spy!` macro to provide a transparent mock but that can be asserted upon. HOT 6
- Feature request: support for `const generics` in `mock!` and `automock` HOT 6
- 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.