I have a problem structuring my tests. In my cargo workspace there is a business
crate, containing business logic and tests. Then I have a test_fixtures
crate, providing mock implementations of business
traits, to be used in the tests of the business
crate as well as the tests of others crates (web
, db
, ...).
The test_fixtures
crate depends on the business
crate, while the business
crate
dev-depends on the test_fixtures
crate. This leads to compiler errors, telling me that I compiled business
twice, with different configurations leading to type errors of types with the same name (one attached below).
So now I'm wondering how I can achieve sharing mocks between several crates. Before, I tried to put the mocks next to the business
tests, but then the mocks are not visible in tests of the web
and db
crate, because when testing web
, its dependencies are not compiled in the #[cfg(test)]
configuration.
error[E0308]: mismatched types
--> business/token_endpoint.rs:1227:9
|
1222 | async fn build_refresh_token(client_id: &str) -> EncodedRefreshToken {
| ------------------- expected `token::EncodedRefreshToken` because of return type
...
1227 | token_creator.finalize_refresh_token(token).unwrap()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `token::EncodedRefreshToken`, found `tiny_auth_business::token::EncodedRefreshToken`
|
= note: `tiny_auth_business::token::EncodedRefreshToken` and `token::EncodedRefreshToken` have similar names, but are actually distinct types
note: `tiny_auth_business::token::EncodedRefreshToken` is defined in crate `tiny_auth_business`
--> /home/unicorn/Programs/tiny-auth/src/rust/business/token.rs:197:1
|
197 | pub struct EncodedRefreshToken(String);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `token::EncodedRefreshToken` is defined in the current crate
--> business/token.rs:197:1
|
197 | pub struct EncodedRefreshToken(String);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: the crate `tiny_auth_business` is compiled multiple times, possibly with different configurations