对DLL中未导出的类进行单元测试

编程入门 行业动态 更新时间:2024-10-21 14:43:26
本文介绍了对DLL中未导出的类进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们使用Visual Studio 2008开发C ++应用程序,并使用Boost.Test进行单元测试.目前,我们有一个单独的解决方案,其中包含我们的单元测试.

We develop a C++ application using Visual Studio 2008 and unit test using Boost.Test. At the moment, we have a separate solution which contains our unit tests.

我们在核心解决方案中的许多项目都产生了DLL.测试范围有限,因为我们无法测试未导出的类.

Many of our projects in the core solution produce DLL's. We're limited in test coverage because we cannot test non-exported classes.

关于如何进行测试,我有两个想法:

I have two ideas on how these could be tested:

  • 导出所有内容
  • 将测试放入DLL(相同的项目和解决方案)中,并使用Boost.Test的外部运行器
  • 我不太确定缺点会是什么.上面的数字1破坏了模块级别的封装,而数字2可能导致更大的DLL,除非可以在某些配置中仅包含测试代码.

    I'm not entirely sure what the drawbacks would be. Number 1 above breaks module level encapsulation, and number 2 could result in a much larger DLL, unless it's possible to only include the test code in certain configurations.

    因此,上述方法是否存在严重缺陷,或者您能想到其他解决方案吗?

    So, are there any severe drawbacks to the above methods, or can you think of other solutions?

    推荐答案

    Tom Quarendon对这个问题的回答使用了西蒙·斯蒂尔(Simon Steele)的回应的一个小变化:

    Expanding on Tom Quarendon's answer to this question, I have used a slight variant of Simon Steele's response:

    • 创建一个测试项目(使用任何喜欢的测试框架,我都使用 CppUnit ).
    • 在您的test_case.cpp中,#include <header/in/source/project.h>.
    • 在测试项目中的属性:
      • 在链接器->常规"中,将源项目的$(IntDir)添加到其他库目录"中.
      • 在链接器"->输入"中,将.obj文件添加到其他依赖项"中.
      • Create a test project (using whatever test framework you like, I use CppUnit).
      • In your test_case.cpp, #include <header/in/source/project.h>.
      • In the test project properties:
        • In Linker->General, add the source project's $(IntDir) to the Additional Library Directories.
        • In Linker->Input, add the .obj files to the Additional Dependencies.

        同样,唯一的维护开销是用于单元测试的标准开销-创建对要测试的单元的依赖性.

        Again, the only maintenance overhead is the standard one for unit tests - to create the dependency on the unit(s) you want to test.

    更多推荐

    对DLL中未导出的类进行单元测试

    本文发布于:2023-11-11 07:42:05,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1577781.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:中未   单元测试   DLL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!