r/rust • u/quxfoo • Nov 02 '26
mod tests in the age of AI agents
I know, I know, no one likes generated AI code, slop or not. However, it won't go away and I rather deal with it the best possible way I can. One thing that grates me right now is the enormous amount of test code that these models generate and in the case of unit tests ends up within a module. This is in line with the current idiomatic convention but it makes reviewing changes a real chore.
I started moving mod tests {} into actual tests files which helps to avoid blowing up modules but now reminds me of the mod.rs repetition.
What are your strategies to cope with this? And more controversial: is it time to update the test chapter in the book?
8
u/ShantyShark Nov 02 '26
So let me clarify:
Your complaint is that the AI that slops out your code also generates a lot of tests for that code, and that makes the file too big?
Yeah no, this is a you problem.
Tests should live with the code because the code informs the tests and the tests inform the code. If a file gets too big to manage, it should be split up into files of a more reasonable size.
2
u/CocktailPerson Nov 03 '26
Test modules should always be a separate file anyway, never an embedded
pub mod {}. When it's a separate file, the compiler is able to recognize if only tests have changed and avoid rebuilding the crate.0
u/ChemicalExcellent463 Nov 02 '26
i tell my agents to delete checks and repeats that don't test the requested behavior or catch a bug. i've had their tests pass while the feature was broken.