Closed zaidoon1 closed 5 months ago
What you posted looks correct. Perhaps the problem lies somewhere else? Are there any other imports?
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..
When do you see the error? Is it when you do cargo build
or cargo test --bin
? What version of Mockall are you using?
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.
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.
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
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
?
sorry, that's my bad, cargo build
works fine.
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:
mock!
in the binary, not #[automock]
in the library.oh i see. thank you!
project directory:
client.rs:
main.rs:
compiler complains with:
If I move
mockall
from dev-dependencies to dependencies in cargo.toml and and update storage.rs to:Things appear to work? But I don't want mockall to be a dependency. What am I doing wrong?