我有以下獲取文件并向其中寫入內(nèi)容的功能。func setFile(file *os.File, appStr models.App) { file.WriteString("1.0") file.WriteString("Created-By: application generation process") for _, mod := range appStr.Modules { file.WriteString(NEW_LINE) file.WriteString(NEW_LINE) file.WriteString("Application") file.WriteString(NEW_LINE) file.WriteString("ApplicationContent") file.WriteString(NEW_LINE) file.WriteString("ContentType") }}為此,我生成如下的單元測(cè)試func Test_setFile(t *testing.T) { type args struct { file *os.File appStr models.App } var tests []struct { name string args args } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { setFile(tt.args.file, tt.args.AppStr) }) }}這里的問題是im取決于文件,為這種功能創(chuàng)建單元測(cè)試的更好方法是什么在正在創(chuàng)建文件的單元測(cè)試中運(yùn)行代碼,然后使用此功能對(duì)其進(jìn)行更新,然后對(duì)其進(jìn)行解析并檢查其值?有沒有更好的方法來實(shí)現(xiàn)這種功能?
- 1 回答
- 0 關(guān)注
- 272 瀏覽
添加回答
舉報(bào)
0/150
提交
取消