I have 2 crates (my code for both): common
& thing
. Inside of my common
crate, I have an immutable struct (pass it all values on creation, can't change them later) Foo
. However, while unit testing my thing
crate, it'd be super helpful to change one of the values in Foo
. I tried the following:
impl Foo {
#[cfg(test)
pub fn change_value(&mut self, new_value: u64) { self.value = new_value; }
}
However, when I run the unit tests for thing
I get a "method not found" error. I'm assuming this is because the test
config is not enabled while compiling common
. I tried adding my common
crate to both [dependencies]
and [dev-dependencies]
, but that didn't do it either.
Is there any way to get my common
create to build with cfg(test)
so that function is compiled and I can call it, but from non-test code it is as if that function doesn't actually exist?