Stevo, that's how I do it. Most of my tests are in an _test package so I can be sure my exported API works. Once in a while I want some extra tests on something not exported so those tests go in a separate source file. And yes, I try to do something with the filename to indicate that it contains in-package tests.
On Tuesday, January 30, 2018 at 8:51:58 AM UTC-5, Stevo Slavić wrote: > > Hello Go community, > > Official docs recommend putting unit tests in same package as package > under test, see: > - https://golang.org/doc/faq#How_do_I_write_a_unit_test > - https://golang.org/pkg/testing/ > > Practical experience (see > https://medium.com/@matryer/5-simple-tips-and-tricks-for-writing-unit-tests-in-golang-619653f90742#03db) > > suggests it's better to put tests to a dedicated package so it can test > exported API only of the package under test, and if there's value to test > the package internals too then put another test suite file to the same > package with a special file name to make it clear it's meant to fiddle with > internals. > > Do these suggestions make sense? If so, would it make sense to make them > official recommended practice? Maybe in Effective Go? > > Kind regards, > Stevo Slavic. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.