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
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.
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
I unit test public APIs with mocks and to cover all error handling, and then a smaller set of integration tests to make sure that the behavior works all the way through. Though for something like a repository pattern, I find hard to test without a real db (except for exceptional
1
1
Fortunately this library is pretty much 100% data manipulation so I don't think I need much in the way of mocking, but that's useful ideas to put in my toolbelt.
Jan 20, 2020 Β· 10:40 PM UTC
1


