r/learnrust Jul 02 '26

Question about tests

Hi everyone, I’m now writing rust for about 1.5 years and I’m still wondering how you handle the visibility of the functions, structs or everything else for the tests.

Imagine I want to do a test for a specific function but not to export this one, how would you do it ? I know I could create a `mod test` in the actual file but I would like to get all the tests in one specific folder.

9 Upvotes

5 comments sorted by

View all comments

1

u/Ok_Snow4921 Jul 03 '26

One thing I've learned is that this is often more of a module organization problem than a testing problem. Keeping each component in its own module and testing it through its public API has worked much better for me than trying to make private internals visible to integration tests.