title: Can I create shared test utilities?
body: <p>I'm wondering whether it's possible to share test utility code across packages in go.  Specifically, I'm writing a TCP server that will be used by multiple handlers for different message types, and want to reuse a set of common test utils.</p>
  
  <p>The main TCP server code is in <code>mypkg/tcpserver</code>:</p>
  
  <pre><code>mypkg/tcpserver/tcp_server.go
  mypkg/tcpserver/tcp_server_test.go
  mypkg/tcpserver/testutils_test.go
  </code></pre>
  
  <p>The <code>testutils_test.go</code> code is intended to be a shared library that can be used by <code>mypkg/tcpserver</code> and other packages to set up a test server and client for their tests.  For example in the <code>handler</code> subpackage I have:</p>
  
  <pre><code>mypkg/tcpserver/handler/handler.go
  mypkg/tcpserver/handler/csv_handler.go
  mypkg/tcpserver/handler/csv_handler_test.go
  mypkg/tcpserver/handler/delim_handler.go
  mypkg/tcpserver/handler/delim_handler_test.go
  </code></pre>
  
  <p>The <code>handler/*_test.go</code> files all import <code>mypkg/tcpserver</code>, but they are unable to access the test utilities defined in <code>mypkg/tcpserver/testutils_test.go</code>:</p>
  
  <pre><code>$ wgo test mypkg/tcpserver/handler
  # mypkg/tcpserver/handler
  src/mypkg/tcpserver/handler/csv_handler_test.go:37: undefined: tcpserver.CreateTestServer
  src/mypkg/tcpserver/handler/csv_handler_test.go:40: undefined: tcpserver.TestSender
  FAIL    mypkg/tcpserver/handler [build failed]
  </code></pre>
  
  <p>It appears that tests can import other packages, but not test code defined within those packages?  Is this the intent?  If so, is there an idiomatic way to share test utilities across packages in go?</p>