duanhuoyao7011 2018-12-01 14:03
浏览 31
已采纳

运行测试,但一个软件包除外

I’ve the following project structure and I want to run go test exclude option to run the test

e.g. Command to Run all tests except the test in the cmd package (I’ve more then 3 packages , the struct below is a simple example)

myGithubProject/ |---- cmd |---- -command |---- -hello.go |---- -hello_test.go |---- internal |---- -fs.go |---- -fs.go |---- -fs_test.go |---- -log |---- -log.go |---- -log_test.go main.go

  • 写回答

1条回答 默认 最新

  • dosin84644 2018-12-01 14:30
    关注

    If you have a hierarchy like that, you may specify the sibling folder to test (and recurse down) like this:

    go test internal/...
    

    If this is not feasible to you (e.g. you have many siblings of cmd, or you have many subfolders inside cmd which you do want to test), you may use build constraints to achieve what you want.

    For example, add an exclusion of a donttestme build tag to the hello_test.go file (the first line):

    // +build !donttestme
    

    And then when you specify this tag when testing, files that exclude this build tag will not be considered (will be skipped):

    go test -tags donttestme <somepackages>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号