How to test the main package functions in golang?

后端 未结 4 1793
情书的邮戳
情书的邮戳 2021-01-03 17:43

I want to test a few functions that are included in my main package, but my tests don\'t appear to be able to access those functions.

My sample main.go file looks li

4条回答
  •  生来不讨喜
    2021-01-03 18:22

    Change package name from main to foobar in both sources. Move source files under src/foobar.

    mkdir -p src/foobar
    mv main.go main_test.go src/foobar/
    

    Make sure to set GOPATH to the folder where src/foobar resides.

    export GOPATH=`pwd -P`
    

    Test it with

    go test foobar
    

提交回复
热议问题