亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在子目錄中“去測試”,只測試與給定模式匹配的測試?

如何在子目錄中“去測試”,只測試與給定模式匹配的測試?

Go
Cats萌萌 2022-09-19 14:53:32
在我的項目中,我有多個包和子目錄。在頂部目錄中,我可以運行,它運行所有子目錄中的所有測試。我已經閱讀了很長一段時間,關于如何只測試與給定模式或測試名稱匹配的測試,但無法找到解決方案。通過瀏覽這些(1 2 3和godocs),我想我可以使用這個:go test ./...go test ./... -run mypattern運行與 mypattern 匹配的測試,但對我來說,它運行所有測試?,F在,我正在使用cd,查找和grep的組合來運行符合我標準的測試。你可以試試這個:git clone https://github.com/grafana/grafana-plugin-sdk-go.git  > go test -run TestJSON  === RUN   TestJSONNotice=== RUN   TestJSONNotice/notice_with_severity_and_text--- PASS: TestJSONNotice (0.00s)    --- PASS: TestJSONNotice/notice_with_severity_and_text (0.00s)=== RUN   TestJSON=== RUN   TestJSON/json.Unmarshal_and_json.Marshal=== RUN   TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error=== RUN   TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data--- PASS: TestJSON (0.00s)    --- PASS: TestJSON/json.Unmarshal_and_json.Marshal (0.00s)        --- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error (0.00s)        --- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data (0.00s)PASSok      github.com/grafana/grafana-plugin-sdk-go/data   0.016s> cd data> go test -run *TestJSON*    zsh: no matches found: *TestJSON*  > go test -run ^TestJSON*    zsh: no matches found: ^TestJSON*    > go test -v -cover --short -race  ./... -run ^TestFloatAt*    zsh: no matches found: ^TestFloatAt*有人可以告訴我如何只測試與給定模式或測試名稱匹配的測試嗎?
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

傳遞符合測試名稱的正則表達式應運行匹配的測試...


例如:


go test -v -cover --short -race  ./... -run ^TestError*

運行不同的測試,這些測試從項目中的測試錯誤開始...


?       github.com/user/project/internal/rabbitmq       [no test files]

=== RUN   TestErrorMiddleware

    printer.go:54: GET http://localhost:45678/surprise

? http server started on [::]:45678

{"error":{"code":"EXPECTED","status":418},"level":"warning","msg":"expected: here's tea","time":"2021-08-06T17:25:58+03:00"}

--- PASS: TestErrorMiddleware (0.01s)

PASS

coverage: 54.8% of statements

ok      ithub.com/user/project/internal/datadog        3.725s  coverage: 70.6% of statements

?       github.com/user/project/internal/ftp    [no test files]

?       github.com/user/project/internal/mongo  [no test files]

testing: warning: no tests to run

PASS

coverage: 0.0% of statements

ok      github.com/user/project/postgres       3.704s  coverage: 0.0% of statements [no tests to run]

ok      github.com/user/project/escrow  7.784s  coverage: 0.0% of statements [no tests to run]

=== RUN   TestError

--- PASS: TestError (0.00s)

=== RUN   TestErrorHandling

--- PASS: TestErrorHandling (0.00s)

PASS

coverage: 70.6% of statements

...

目標對象是測試的名稱(函數名稱以Test)


查看完整回答
反對 回復 2022-09-19
  • 1 回答
  • 0 關注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號