go test 提示 no test files

文章目录

    由于我的 golang 测试代码写在子目录下,而项目根目录下没有任何测试代码文件。所以在执行测试时,提示 no test files。

    go test -v
    ?       sunzhongwei.com/go_tool [no test files]
    

    解决方法一

    > go test -v ./...
    ?       sunzhongwei.com/go_tool [no test files]
    ?       sunzhongwei.com/go_tool/controllers     [no test files]
    ?       sunzhongwei.com/go_tool/models  [no test files]
    === RUN   TestIsMobile
    --- PASS: TestIsMobile (0.00s)
    PASS
    ok      sunzhongwei.com/go_tool/utils   0.029s
    

    解决方法二

    进入子目录执行:

    > cd utils/
    > go test -v