Golang tests in sub-directory

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

    I normally don't do test, but you can group your file into directories and use import like

    import "./models" if is one level out
    import "../models if is one level out and one level in

    For example, for:
    ./models/todo.go
    ./test/todo_test.go

    to test todo.go from todo_test.go, your import in the todo_test.go will be

    import "../models"

提交回复
热议问题