doulie0178 2018-04-20 07:13
浏览 16
已采纳

随时进行单一测试

I have two tests in my project, I would like to build a single test, place the resulting binary in a container, run it, and then attach a debugger.

Is this possible?

package dataplatform

import "testing"

func TestA(t *testing.T) {

    // test A
}

func TestRunCommand(t *testing.T) {

    // Test B
}
  • 写回答

1条回答 默认 最新

  • duanpaxin3531 2018-04-20 07:33
    关注

    You may use -run <regexp> to limit (filter) the tests to run. So for example if you want to run only the TestA() test, you may do it like this:

    go test -run TestA
    

    Actually the above will run all tests whose names contain TestA, so to be explicit, it would be:

    go test -run ^TestA$
    

    To not run the tests but generate the test binary, you may use the -c option:

    go test -c
    

    This won't run the tests, but compile a binary which when executed will run the tests.

    The problem is that you can't combine these options, e.g. running

    go test -c -run TestA
    

    Will generate a binary which when executed will run all tests.

    The truth is that the generated binary accepts the same parameters as go test, so you may pass -run TestA to the generated binary, but you must prefix the params with test:

    Each of these flags is also recognized with an optional 'test.' prefix, as in -test.v. When invoking the generated test binary (the result of 'go test -c') directly, however, the prefix is mandatory.

    So if the name of the generated test binary is my.test, run it like:

    ./my.test -test.run TestA
    

    For more options and documentation, run go help test, or visit the official documentation:

    Command Go

    And the relevant section:

    Command Go: Testing flags

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效