Test code organization in a multi-crate setup

Is there a way to specify that crate foo, which depends on crate bar, needs bar to be built in the test configuration, when foo itself is built in the test configuration? The reason I need this is that bar exposes some mock objects that are needed in foo's tests, but I wanted them to be compiled only when bar itself is configured for testing.

No, dependencies never have #[cfg(test)] enabled.