Multiple testcase in a sequence in GO

huangapple go评论79阅读模式
英文:

Multiple testcase in a sequence in GO

问题

尽管Go语言允许使用命令"$go test packagename"按顺序运行多个测试文件,但是否有一种方法可以使用文本文件来控制这个顺序呢?

例如:textfile 只需包含要按顺序运行的所有测试用例文件的名称,以便用户只需修改此文本文件即可运行所需的测试用例,类似于 "$go test textfile.txt"。是否有一种可以自定义的方式来实现这一点呢?

英文:

Although Go language allows to run multiple test files in a sequence by using the command $go test packagename ,

is there a way to control this sequence using a textfile.

Like for eg: textfile should just contain the names of all the testcase files to be run in a sequence so that the user just modify this textfile to run the desirable testcases

like $go test textfile.txt
Is there a way of customizing in this way?

答案1

得分: 4

go test命令允许您使用go test -test.run <regex>指定要运行的测试函数。例如,您可以编写一个小的bash脚本或别名:

FILE=$1 # 第一个参数
cat $FILE | while read regex; do # 逐行读取文件
    go test -test.run "$regex"
done

然后,您可以执行./myscript.sh testFuncs.txt,例如。

英文:

The go test command allows you to specify test functions to run using go test -test.run &lt;regex&gt;. You could, for example, write a little bash script or alias:

FILE=$1 # first argument
cat $FILE | while read regex; do # read file one line at a time
    go test -test.run &quot;$regex&quot;
done

and then you could do ./myscript.sh testFuncs.txt, for example.

huangapple
  • 本文由 发表于 2014年8月20日 13:36:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/25397378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定