Question for all the @rustlang hackers out there -- Do you prefer #[cfg(test)] stuff in your crate, or code in the tests/*.rs files for testing the majority of your code when your library is almost entirely public API?
13
2
1
14
The first is a unit test, whereas the second is an integration test. You'll always want both β€” unit tests for private internals, and integration tests for testing the API.
1
4
Replying to @mmstick @rustlang
Yeah, but where do I draw the line when 99% of the API is public? Do I bother with unit tests for specific testing, or do I try and cover all the code by means of integration tests? What about examples, do they count for coverage, or not? Such are my Monday evening ponderings.

Jan 20, 2020 Β· 10:31 PM UTC

2
1
I consider doc tests separate from unit/integration tests. To me, those are more for validating that the user friendly docs are actually correct, while my unit tests and integration tests cover all of the other cases.
3
1
Yeah that's how I feel I ought to be treating this -- the doctests just show that I've not written bad examples. I'm just trying to decide between unit tests and integration tests for this. Perhaps I should sleep on the problem :D
1
integration tests are more sensitive to API changes, and whole purpose of tests existing is finding broken parts on refactoring - bigger API you have, more important integration tests become.