dousenjue3214 2019-04-05 01:17
浏览 51

在测试表中转换黄金文件和输入文件

I'm trying to find a way to create a test table from golden and input files.

I have the following dir structure:

pkg
|
| mypackage/
  | testdata/
    | file1.input
    | file1.golden
    | file2.input
    | file2.golden
  | mypackage_test.go
  | ...

I'm trying to find an efficient way to create a test table from a pair of input and golden files:

type test struct {
   input,
   expected string
}

func getFiles() test {
  input, _ := ioutil.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.%s", filename, "input")))
  expected, := ioutil.ReadFile(filepath.Join("testdata", fmt.Sprintf("%s.%s", filename, "golden")))
  return {string(input), string(expected)}
}

func getTable() []test {
  return []test{getFiles("file1"), getFiles("file2"), getFiles("file3")}
}

func TestInputs(t *testing.T) {
  table := getTable()
  for _, tt := range table {
    // perform the test
  }
}

I'm not really the best at writting tests, and the code above seems a bit hacky. Is there a better way to do what I'm trying?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)