How to run test cases in a specified file?

前端 未结 7 1645
孤独总比滥情好
孤独总比滥情好 2020-12-04 05:30

My package test cases are scattered across multiple files, if I run go test it runs all test cases in the package.

It is unnecessar

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 06:18

    @zzzz's answer is mostly complete, but just to save others from having to dig through the referenced documentation you can run a single test in a package as follows:

    go test packageName -run TestName
    

    Note that you want to pass in the name of the test, not the file name where the test exists.

    The -run flag actually accepts a regex so you could limit the test run to a class of tests. From the docs:

    -run regexp
        Run only those tests and examples matching the regular
        expression.
    

提交回复
热议问题