单元测试的建议
您好,关于调试的另一个问题:当我知道参数集时自动生成测试用例。并一次完成所有这些,而不是在开发过程中(可能会踢自己)
我有一组我希望测试的软件参数。 (仅约 12 个参数)。然而,当然这些参数通常是整数,因此对于每个参数,我可以有 4 个有意义的值(0,非常大,通常大,通常小)。
有没有一种方法可以自动生成我的测试用例?会节省我很多时间。我已经必须手动检查每个测试用例,不是吗?我的很多程序都会向控制台生成输出,因此正常的断言可能不起作用,而且我大部分时间都在自制数据结构上工作,所以我无法使用简单的断言。
我梦想的选择是一种反向正则表达式,我在其中设置规则并生成一些可以用作输入的文件(我的软件有一种粗糙的脚本语言)。这样我就可以组装所有输入文件并一一测试它们。
期待听到您的好意建议。
干杯
Hello another question concerning debugging : Automatically generating test cases when i know the parameterset. And doing it all at once, instead during development (could kick myself)
i have a set of parameters for my software that i wish to test. (~ 12 parameters only). However of course these parameters are often integers, so for every parameter i can have 4 values that make sense(0, insanely huge, normally big, normally small).
is there a way i can generate my testcases automatically? would save me a lot of time. I already have to inspect every test case by hand, do i not? Alot of my program produces output to the console so normal assertions probably wont work, also i work on home made datastructures most of the time, so i could not use a simple assertion.
My dream option would be kind of a reverse regular expression, where i set the rules and get myself some file generated that i can use as an input (my software has a crude scripting language). that way i can assemble all input files and test them one by one.
Looking forward to listening to your kind suggestions.
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有很多方法可以在您的场景中生成测试用例 - 尽管您对程序和单元的输入需要采取什么形式有点模糊。对于我的 Fortran 程序之一,我使用模板输入参数文件、bash 脚本和 make 文件。当在测试假目标上调用 make 文件时:
a) 编译程序;
b) 运行 bash 脚本,该脚本使用 sed 替换模板参数文件中的占位符,以创建 128 个(或其他)测试输入文件;
c) 将所有测试作业提交到集群上的作业管理系统。
一旦他们的工作完成,我就会有一些其他脚本来将输出与基准进行比较,收集统计数据,诸如此类的事情。
如果您需要更具体的建议,请发布更具体的问题。
编辑:在 bash 脚本中使用 sed:
假设参数输入模板文件包含 3 个要替换的代码:$FREQ$、$NUM$ 和 $TOL$。然后我编写了一个带有 3 层深循环嵌套的 bash 脚本,如下所示:
它并不漂亮,但它可以工作,并且它使我不必费力处理更复杂的解决方案,例如 xUnit 测试或 Python 编程。
There are lots of ways to generate test cases in your scenario -- though you're a bit vague on what form the inputs for your programs and units need to take. For one of my Fortran programs I use a template input parameter file, a bash script and a make file. The make file, when called on the test phony target:
a) compiles the program;
b) runs the bash script, which uses sed to replace placeholders in the template parameter file, to create 128 (or whatever) test input files;
c) submits all the test jobs to the job management system on our cluster.
Once they jobs have finished I have some other scripts to compare outputs with benchmarks, collect statistics, that sort of thing.
If you need more specific advice, post more specific questions.
EDIT: Using sed inside a bash script:
Suppose that the parameter input template file contains 3 codes to be replaced: $FREQ$, $NUM$ and $TOL$. Then I write a bash script with a 3-deep loop nest something like this:
It's not pretty but it works, and it saves me wrestling with much more sophisticated solutions such as xUnit testing or Python programming.
我建议您阅读一些有关数据驱动单元测试的内容。
有很多框架可以帮助您做到这一点。
您可以从这里开始: http://www.slideshare.net /dnastacio/datadriven-unit-testing-for-java-1933154。
I suggest you read something about data-driven unit testing.
There are lots of frameworks that can help you with that.
You may start here: http://www.slideshare.net/dnastacio/datadriven-unit-testing-for-java-1933154.
我发现您使用 FORTRAN,并且可能使用 FORTRAN 版本的 xUnit 之一。作为 JUnit 的用户,我建议 参数化测试 - 看看这个概念是否适用于您的情况。
I see that you work with FORTRAN and you probably deal with one of FORTRAN's versions of xUnit. Being user of JUnit I'd suggest parameterized tests - see if the concept applies in your case.