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

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

表驅動的文件創建測試

表驅動的文件創建測試

Go
開心每一天1111 2021-04-06 13:14:50
我從@volker得到了一個有關表驅動測試的示例,如下所示,但是目前我錯過了我應該在真實測試中放入的內容,該測試使用的是字節,目前我不確定要在args和中放入什么expected []byte,例如,我想檢查一下在文件中存在2 new line然后application輸入,我該如何做而無需創建真實文件并對其進行解析?type Models struct {    name        string    vtype       string    contentType string}func setFile(file io.Writer, appStr Models) {    fmt.Fprint(file, "1.0")    fmt.Fprint(file, "Created-By: application generation process")    for _, mod := range appStr.Modules {        fmt.Fprint(file, "\n")        fmt.Fprint(file, "\n")        fmt.Fprint(file,  appStr.vtype) //"userApp"        fmt.Fprint(file, "\n")        fmt.Fprint(file, appStr.name) //"applicationValue"        fmt.Fprint(file, "\n")        fmt.Fprint(file, appStr.contentType)//"ContentType"    }}func Test_setFile(t *testing.T) {    type args struct {        appStr models.App    }    var tests []struct {        name string        args args        expected []byte   }    for _, tt := range tests {        t.Run(tt.name, func(t *testing.T) {            b := &bytes.Buffer{}            setFile(b, tt.args.AppStr)            if !bytes.Equal(b.Bytes(), tt.expected) {                t.Error("somewhat bad happen")            }        })    }}我閱讀并理解了以下示例,但不了解字節和文件 https://medium.com/@virup/how-to-write-concise-tests-table-driven-tests-ed672c502ae4
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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