Golang tests in sub-directory

前端 未结 4 1287
天涯浪人
天涯浪人 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:44

    EDITED

    Built on VonC's answer,

    This answer is valid in go1.11. No yet tested in upper go versions.

    For those of you who like to keep their tests in a sub-folder, say test, then running

    go test ./...
    

    will attempt to run tests in every folder, even those that do not contain any test, thus having a ? in the subsequent report for non-test folders.

    Running

    go test ./.../test
    

    instead will target only your test folders, thus having a clean report focused on your tests folders only.

    CAUTION

    Please be mindful that using test sub-folders will prevent coverage report computation. The phylosophy of go is to leave test files in the package folders.

提交回复
热议问题