Giter Site home page Giter Site logo

Comments (10)

asomers avatar asomers commented on August 22, 2024

What you posted looks correct. Perhaps the problem lies somewhere else? Are there any other imports?

from mockall.

zaidoon1 avatar zaidoon1 commented on August 22, 2024

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.

asomers avatar asomers commented on August 22, 2024

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.

zaidoon1 avatar zaidoon1 commented on August 22, 2024

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.

asomers avatar asomers commented on August 22, 2024

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.

zaidoon1 avatar zaidoon1 commented on August 22, 2024

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.

asomers avatar asomers commented on August 22, 2024

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.

zaidoon1 avatar zaidoon1 commented on August 22, 2024

sorry, that's my bad, cargo build works fine.

from mockall.

asomers avatar asomers commented on August 22, 2024

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.

zaidoon1 avatar zaidoon1 commented on August 22, 2024

oh i see. thank you!

from mockall.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.