Guidelines: Naming of unit test module


#1

Several people (see e.g. issues #23839, #23870, #24030) noticed that the testing chapter of the book used a module called “tests” to hold unit tests but the style guidelines state that unit tests should live in a module named “test”. I tried to rename all unit test modules in rust-lang/rust from “tests” to “test” but this does not work in every case, as some crates publicly export a module named “test” or use libtest (see the PR here).
Alex Crichton suggested gathering more opinions about “what the convention should be here, if any”, so I followed his advice and opened this post here for discussion.

TL;DR: Should there be a convention for the naming of unit test (sub-)modules and, if yes, what should the name be (test or tests or …)?


#2

I think you mean you tried to rename all such modules test (from tests).

The presence of libtest is exactly why I started using mod tests { ... } a long time ago, and haven’t looked back since.


#3

Of course, I have corrected this in the original post. :smile:


#4

+1 for mod tests: I use it for the same reason (b/c of libtest).


#5

I ran into this the other day, so +1 for tests too.


#6

+1 for mod tests as I wrote on GitHub issue #24030