嵌入式系统的单元测试 [英] Unit testing for embedded system
问题描述
我有一个产品可以在最终产品硬件上的 Vxworks 上运行.但是开发是在 Visual Studio 中使用交叉编译器完成的,然后下载到硬件进行测试.我打算为产品编写单元测试用例.我的问题是因为我的开发是在 Windows 上完成的,我如何运行单元测试用例,因为它与真实场景不相似?
I am having a product which runs on Vxworks on end product hardware. But development is done in Visual studio using cross compiler and downloaded to hardware for testing. I am planning to write unit test cases for product. My question is because my development is done on windows and how can I run unit test cases as it is not resemebling real scenario?
欢迎任何输入
推荐答案
我怀疑您的代码通过系统调用与 VxWorks 进行了大量交互.将抽象层放入其中会很困难.
I suspect that you have code that interacts a lot with VxWorks through system calls. Putting a layer of abstraction in there will be hard.
你使用的是 c 还是 c++?
Are you using c or c++?
如果您使用的是 C++ 并且您可以识别系统的以下部分:
If you are using c++ and you can identify parts of the system that:
- 经常发生变化;和
- 主要处理内部数据;或
- 仅与周围系统的预定义/形式化子集相关(例如协议处理或单独的 PLC 控制逻辑模块).
然后你应该首先在模块和系统的其余部分之间注入 c++ 接口.该模块应仅与接口/适配器相关.然后你就有了一个独立的部分,可以捆绑到一个 Visual Studio 测试工具中.
Then you should first inject c++ interface(s) between the module and the rest of the system. This module should only relate to the interface(s)/adapter(s). Then you have an isolated piece that can be strapped into a visual studio test harness.
然后,您应该尝试确定系统中容易出现错误的区域,这些区域可能会受到(频繁)更改或审核的影响.您可能永远无法在目标系统上实现 50% 的覆盖率,但您可以实现一个系统,其中 90% 的日常编码发生在覆盖的 40% 代码库内.
Then you should try to identify areas in your system that are error prone to bugs, subject to (frequent) change or audit. You will probably never achieve even 50% coverage on the target system, but you can achieve a system where 90% of the daily coding happens within the covered 40% of the code base.
这篇关于嵌入式系统的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!