且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

嵌入式系统的单元测试

更新时间:2023-12-03 13:49:52

我怀疑您的代码通过系统调用与 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.