Golang tests in sub-directory

前端 未结 4 1293
天涯浪人
天涯浪人 2021-01-29 22:16

I want to create a package in Go with tests and examples for the package as subdirectories to keep the workspace cleaner. Is this possible and if so how?

All the docume

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 22:59

    Put your tests alongside your code in the same directory in a file called file_test.go where "file" is the name of the source code file you're testing. This is convention and I've found it to be best in my own experience.

    If the go test tool isn't quite automated enough for you, you might look into GoConvey, which has a web UI that will automatically update and run traditional Go tests as well as GoConvey tests (which are based on behavior, and are more self-documenting than traditional Go tests).

提交回复
热议问题