Function in same package undefined

前端 未结 9 2045
太阳男子
太阳男子 2020-12-28 12:17

My project structure is like this.

packagetest/
    main.go
    lib.go

In main.go, I have this code.

package m         


        
9条回答
  •  再見小時候
    2020-12-28 12:53

    • lib.go should be renamed to main_test.go
    • The function signature of the test function should be func Test(t *testing.T) {
    • The package testing should be imported in main_test.go.
    • Ideally, the Test function should have a name that reflects what it is testing, like TestPrinting.

    Then both go build and go test should work.

提交回复
热议问题