Proper package naming for testing with the Go language

前端 未结 4 1325
无人及你
无人及你 2020-12-02 04:08

I have seen several different test package naming strategies within Go and wanted to know what pros and cons of each are and which one I should use.

Strategy

4条回答
  •  孤城傲影
    2020-12-02 04:30

    It depends on the scope of your tests. High level tests (integration, acceptance, etc...) should probably be placed in a separate package to ensure that you are using the package via the exported API.

    If you have a large package with a lot of internals that need to be put under test then use the same package for your tests. But that's not an invitation for your tests to access any bit of private state. That would make refactoring a nightmare. When I write structs in go I am often implementing interfaces. It is those interface methods that I invoke from my tests, not all of the helper methods/functions individually.

提交回复
热议问题