• 0 Posts
  • 8 Comments
Joined 3 years ago
cake
Cake day: July 29th, 2023

help-circle



  • Your specific question is answered here: https://www.sobyte.net/post/2023-04/go-test-path-main/.

    Well, here’s the problem! This _testmain.go is the main package of the test executable generated by go test, and it now imports a “main” package, which is not allowed in Go.

    Generally this is easily solved by moving the code you are testing to a package for example pkg/todo.go and pkg/todo_test.go or utility or whatever.

    Finally if you look at that link i sent they recommend not testing main in exactly the way you are testing it. One negative of the way you are testing it is you aren’t really unit testing – every time you run main_test you compile main, this is a little unusual.