为了账号安全,请及时绑定邮箱和手机立即绑定

创建单元测试以使用内容创建文件

创建单元测试以使用内容创建文件

Go
慕森王 2021-04-04 17:14:00
我有以下获取文件并向其中写入内容的功能。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")    }}为此,我生成如下的单元测试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取决于文件,为这种功能创建单元测试的更好方法是什么在正在创建文件的单元测试中运行代码,然后使用此功能对其进行更新,然后对其进行解析并检查其值?有没有更好的方法来实现这种功能?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 230 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信