How does one test net.Conn in unit tests in Golang?
Clash Royale CLAN TAG #URR8PPP How does one test net.Conn in unit tests in Golang? I'm currently looking into creating some unit tests for net.Conn interface in Go, as well as other functions that build up on top of that functionality, and I'm wondering what is the best way to unit test that in Google Go? My code looks like: conn, _:=net.Dial("tcp", "127.0.0.1:8080") ... fmt.Fprintf(conn, "test") ... buffer:=make(byte, 100) conn.Read(buffer) Is the most efficient way of testing this code and the code that uses these functions to spin up a separate goroutine to act like the server, use net.http.httptest package, or something else? Suggest reading the source for the tests for the actual net library. I have picked up plenty of tips by doing that in the past. Secondly as you have already mentioned use the httptest package. – miltonb Jun 7 '15 at 4:31 ...