DEV Community

Golang - test doubles, where to keep?

Patryk Woziński on June 27, 2022

Hey! I am wondering where should I put my test doubles like Spy/Stub/Dummy implementations of specific interfaces. What do you think? I'm of cours...
Collapse
 
fjones profile image
FJones

The canonical answer (as implemented in the standard library), is as follows:

  • keep stubs in the same _test.go as the actual tests wherever reasonably possible
  • otherwise (e.g. if you share test stubs), place them in a package of their own, which itself contains the word "test" (see http/httptest for example)