On Tue, Jan 30, 2018 at 4:45 AM, Stevo Slavić <ssla...@gmail.com> wrote:
>
> 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?

Go already supports both approaches.  Internal tests of package p are
themselves in package p.  External tests are in package p_test.  In
both cases the tests can be in the same directory in xxx_test.go
files.  This is documented at
https://golang.org/cmd/go/#hdr-Test_packages .  Effective Go doesn't
seem to say anything about testing today.  If we think we need to say
something, a blog article might be a better approach.

Ian

-- 
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.

Reply via email to