C嵌入式自动单元测试生成
是否有任何软件可以在 C 和嵌入式应用程序中生成单元测试?我之所以问这个问题,是因为我的老板告诉我,他听某人说“你需要一个工具来分析代码并自动创建 80% 的相关测试用例,剩下的 20% 需要你用所有的时间并专注于”,否则这将花费“太多时间”。
我对这种说法非常怀疑,并且无法清楚地看到可以自动生成什么样的测试以及它们是否有任何好处。
不过,我可以看到可以为 API 自动生成接口单元测试。
那么有人可以告诉我这个问题吗?
Is there any SW to generate unit tests in C and embedded applications? The reason I am asking is that my boss told me he heard from someone that "You need a tool to analyze the code and create 80% of all relevant testcases automatically, the remaining 20% you use all your time and focus on", else it would take "too much time".
I am very skeptic about this statement and can't see clearly what kind of tests that could be auto generated and if they would be any good at all.
I can, however, see that it would be possible to generate interface unit tests automatically for the API:s.
So can someone enlighten me on this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我推荐 API Sanity Checker 工具:
独特功能:
请参阅 自由类型2。
我是该项目的作者,您可以向我询问有关该项目的任何问题。
I recommend API Sanity Checker tool:
Unique features:
See examples for FreeType2.
I'm author of this project and you can ask me any questions on it.
你的老板搞错了方向。
据我所知,没有任何工具可以为您生成单元测试。
他可能错误的是代码覆盖率和单元测试。虽然相关,但它们实际上是不同的问题。
代码覆盖率将检测您的代码,一旦运行完成,您就可以了解运行中使用了多少源代码。这在单元测试时非常有用,因为它将有效地向您显示已测试的位置以及需要将工作重点放在何处。
覆盖前三分之二的代码相当容易,但收益递减意味着要接近神奇的 100% 需要花费大量的时间和精力。
Your boss has got the wrong end of the stick.
I know of no tools that will generate unit tests for you.
What he may be mistaking is code coverage and unit testing. While related they are in fact separate issues.
Code coverage will instrument your code and once finished running give you the low down on how much of your source was used in the run. This is useful when unit testing as it will effectively show you where you have tested and where you need to focus your work.
It is fairly easy to get the first two thirds of code covered but diminishing returns means to get near a magic 100% takes a lot of time and effort.
谷歌搜索“单元测试生成器”会发现很多东西,但我不知道它们是否有任何好处,或者它们是否适合您的情况。
这不是单元测试,但您可以使用 lint 或相关工具进行一些代码检查。请参阅:http://www.lysator.liu.se/c/ten- commandments.html 我认为当前的一个开源工具是splint http://www.splint.org/< /a>
Jon Bentley 的书籍对“脚手架”代码(包括测试脚手架)的作用进行了一些很好的讨论。
Googling "unit test generator" turns up a lot of things, but I do not know if they are any good, or if they'll suit your case.
It is not unit testing, but you can do some code checking with lint or related tools. See: http://www.lysator.liu.se/c/ten-commandments.html I think a current open source tool is splint http://www.splint.org/
Jon Bentley's books have some good discussion of the role of "scaffolding" code, including test scaffolds.
首先,单元测试和生成单元测试是什么意思?
您的意思是生成一个框架、一个测试工具,还是生成一个带有数据和数据检查或实际调用您的代码的断言的测试。并且,在后一种情况下,该测试是如何生成的?
更根本的是,你为什么要测试?您是否遵循需要一定级别测试的标准,或者您“只是”试图降低开发后期阶段的风险和成本?或者,您可能正在现有系统上构建,只是想确保不会破坏任何现有功能。
之前的答案提到了 Cantata,我们最近发布了一个新版本,其中包含一个名为“基线测试”的组件。这可能正是您正在寻找的。它将为 C 代码创建一组单元测试,其中包含很有可能充分运用每个源文件的测试用例。该工具通过读取您的源代码并生成一组测试来实现这一目标,这些测试驱动每条路径的执行,旨在实现您期望的覆盖率目标——100% 的声明、决策甚至 MC/DC 覆盖率。目的是作为遗留系统持续开发的一部分对源代码进行“基准化”,或者在功能测试或系统测试后填补覆盖范围的空白。
请参阅 Cantata++ 网页了解更多信息(和免费评估)
First of all, what do you mean by unit test and generate unit tests?
Do you mean generate a framework, a test harness or do you mean generate a test with data and data checks or assertions that actually calls your code. And, in the latter case, how is that test generated?
More fundamentally, why are you testing? Are you following a standard that requires a certain level of testing, or are you 'just' trying to reduce risk and cost in later stages of development? Or maybe you are building on an existing system and just want to make sure you do not break any existing functionality.
A previous answer mentioned Cantata, we have recently released a new version with a component called 'baseline testing'. This may be just what you are looking for. It will create, for C code, a set of unit tests, containing test cases that stand a good chance of fully exercising each of your source files. The tool achieves this by reading your source and producing a set of test that drive the execution down each path aiming to achieve your desired coverage target – 100% statement, decision or even MC/DC coverage. The intent is to 'baseline' your source code as part of the ongoing development of a legacy system, or to fill in coverage gaps after functional or maybe system testing.
See the Cantata++ webpage for more information (and free evaluations)
我们在这里使用 CANtata 来生成单元测试/代码覆盖率。它很不错,尽管我认为它有点贵。
We use CANtata here where I work for generating unit tests / code coverage. Its decent, though I imagine it is a bit pricey.
我们使用 IBM RTRT
http://www-01.ibm。 com/software/awdtools/test/realtime/index.html
虽然在我们的用例中我们不使用它来生成测试,但我看到了至少生成骨架的一些可能性。
We use IBM RTRT
http://www-01.ibm.com/software/awdtools/test/realtime/index.html
Although in our use case we don't use it to generate the tests, but I saw some possibilities to generate at least skeleton.
是的。 IBM的Rational Test Realtime将是不错的选择。
不。没有任何工具可以为所有类型的 C 源代码完成这项工作。
但对于某些情况是可以的。例如,就我而言,我有大量的C源代码需要由客户测试。但是因为每个源文件都非常相似,所以我们制作了一个小工具来读取每个文件并生成测试用例(到单元测试工具的脚本语言),然后由单元测试工具执行。是的,在这种情况下,它可以节省 80% 的精力。
所以你可以考虑这样做,找出类似的源代码,并制作自己的工具来生成类似的测试用例。
Yes. Rational Test Realtime of IBM will be the good choice.
No. There is no tool that can do this work for all type of C source codes.
But yes for some cases. For example, in my case, I have big amount of C source codes are required to be tested by customer. But because every source file are quite similar, so we make a small tool that read each file and generate test case (to the scripting language of the Unit Testing Tool) and then execute by the Unit Testing Tool. And yes, in this case, it saves 80% effort.
So you could consider to do this, find out the similar source codes, and make your own tool that can generate test case for the similar.