Running tests and skipping some packages

前端 未结 1 1781
面向向阳花
面向向阳花 2021-01-07 19:43

Is it possible to skip directories from testing. For example given the structure below is it possible to test mypackage, mypackage/other and mypackage/net but not mypackage/

相关标签:
1条回答
  • 2021-01-07 20:28

    Go test takes a list of packages to test on the command line (see go help packages) so you can test an arbitrary set of packages with a single invocation like so:

    go test import/path/to/mypackage import/path/to/mypackage/other import/path/to/mypackage/net

    Or, depending on your shell:

    go test import/path/to/mypackage{,/other,/net}


    You might be able to use interesting invocations of go list as the arguments (again, depending on your shell):

    go test `go list`
    

    Your comment says you want to skip one sub-directory so (depending on your shell) perhaps this:

    go test `go list ./... | grep -v directoriesToSkip`
    

    as with anything, if you do that a lot you could make a shell alias/whatever for it.


    If the reason you want to skip tests is, for example, that you have long/expensive tests that you often want to skip, than the tests themselves could/should check testing.Short() and call t.Skip() as appropriate.

    Then you could run either:

    go test -short import/path/to/mypackage/...

    or from within the mypackage directory:

    go test -short ./...

    You can use things other testing.Short() to trigger skipping as well.

    0 讨论(0)
提交回复
热议问题