Convention for releasing code to help with testing

what's the convention for releasing test utilities alongside a library? a feature named "testkit" or similar? a separate crate?

is there a way to enforce that such code is only usable in development/testing (or other testing libraries), or at least only enabled in testing by default?

1 Like

what's the convention for releasing test utilities alongside a library? a feature named "testkit" or similar? a separate crate?

I am not aware of such a convention; most libraries do not have any test utilities, and those that do usually have only a few functions that might even be always-enabled. I would say, treat it as any other optional code.

is there a way to enforce that such code is only usable in development/testing (or other testing libraries), or at least only enabled in testing by default?

No. There is no such thing as visibility to tests only. Whether code “is a test” only affects the build of the crate containing the #[test] functions, and nothing else.

1 Like

Putting #[test] above your function will assure it is not used execept for testing purposes.

That isn't what it does. #[test] declares something as an actual executable test. You may be thinking about #[cfg(test)], but that isn't applied to dependencies as far as I know.

1 Like