在现有库 ProjectGroup 中组织单元测试
在我们的 Delphi2007 环境中,我们有一个 SGLibrary groupproj,其中包含大约 30 个 bpl。我们刚刚开始为这些库创建单元测试,并且不确定组织单元测试项目的最方便的方法是什么。
我们倾向于为每个 bpl 创建一个测试可执行文件,因为这将使编译运行变得简单快速。可以将 test-exe 设置为活动项目,并可以通过设置依赖项来强制编译 bpl。运行测试也很容易,即通过将测试可执行文件设置为 bpl 的主机应用程序。
但缺点是库组项目将扩展为另外 30 个项目,使其成为一个非常大的组(为什么我们不能在 Delpi 中创建子组???)。
相反的安排是创建 1 个测试可执行文件,其中包含所有单元测试,但这将创建一个包含一百多个单元的可执行文件,以及许多依赖项,在运行单个测试之前都必须编译所有依赖项。
所以我的问题...是否有人对如何将其组织成可管理且快速运行的设置有任何建议、最佳实践或其他想法?
额外的考虑:我们希望能够一次运行所有测试,当然,如果我们将所有测试放在一个可执行文件中,这会更容易。
In our Delphi2007 environment we have a SGLibrary groupproj which contains some 30 bpls. We're just starting out creating unittests for these libraries and are not sure what the most convenient way of organizing the Unittest projects would be.
We are inclined to create a test-executable for each bpl, as this will make compilation an running easy and fast. The test-exe can be set as the active project and Compilation of the bpl can be forced by setting a dependency. It is also easy to run tests, ie by setting the test-executable as the Hostapplication of the bpl.
But the downside is that the library groupproject will be expanded with another 30 items, making it a very large group (why can't we make subgroups in Delpi ???).
The opposite arrangement would be to create 1 test executable which contains all unit-tests but that would create a executable with over a hundred units, and lots of depencies which all have to be compiled before a single test can be run.
So my question ... Does anybody have any suggestions, best practices, or other ideas on how to organize this into a manageable and fast running setup?
Extra consideration: We want to have the possibility to run all tests at once, and of course this will be easier in we put all tests in one executable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DUnit 有一个鲜为人知的功能支持从 dll 运行测试。您基本上创建了一个 dunit exe 项目,它没有自己的测试,而是从 dll 加载测试。
每个 dll 需要导出一个函数:
然后您只需像平常一样将测试用例添加到 dll 中即可。测试会自动注册在每个单元的初始化部分中。
恕我直言,遗憾的是这没有被推广为使用 DUnit 的标准方式。大多数其他语言的单元测试框架都是以这种方式组织的。它们提供单个测试运行程序可执行文件,可以从任意数量的可加载模块动态加载测试用例。
除了让您分解测试以便于组织之外,它还允许您在多个场景下运行相同的测试。也许您希望使用调试和发布版本的不同编译器选项(甚至不同版本的编译器)来运行测试,以便您更有信心代码的行为一致。您可以从同一源构建多个 dll,并在同一会话中运行它们。
There is a little known feature of DUnit that supports running tests from a dll. You basically create a dunit exe project that has no tests of its own, rather it loads tests from dlls.
Each dll needs to export a single function:
Then you just add test cases to the dll as normal. The tests are automatically registered in each unit's initialization section.
IMHO its a pity this isn't promoted as the standard way of working with DUnit. Most unit testing frameworks for other languages are organized this way. They provide a single test runner executable which dynamically loads test cases from any number of loadable modules.
In addition to letting you break up your tests for easier organization it also allows you to run the same tests under multiple scenarios. Perhaps you want to run your tests using different compiler options for your debug and release builds (or even different versions of the compiler) so you are more confident that the code behaves consistently. You can build multiple dlls from the same source and run them in the same session.
我可能会两者都做,所以你最终会得到这样的结果:
你可以使用你的持续集成系统中的最终项目,前者用于测试尚未签入的东西。
这确实是一个大量的项目,是你为能够提高代码质量而付出的代价。
——杰罗恩
I'd probably do both, so you end up with this:
You can use the final project in your continuous integration system, and the former for testing things that are not yet checked in.
This is indeed a large number of projects, a price you pay for being able to improve the quality of your code.
--jeroen