本文介绍了如何为同一发行版中的多个 Perl 模块设计单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个内部框架,它是用一堆 Perl 模块设计的.所有这些模块都依赖于一个公开一些 Win32 功能的模块.例如A、B、C、D 等模块都依赖于单个模块 Z.因此所有这些模块都将通过use MyFramework::Z"导入.所有这些模块 A、B、C 等都可以单独使用 &不依赖于任何其他框架模块.

I have been developing an internal framework which is designed with bunch of Perl modules. All these modules are dependent on a single module that exposes some Win32 functionality. For e.g. A, B, C, D, etc modules all depend on a single module Z. So all these modules will import by "use MyFramework::Z". All these modules A,B,C etc can be used individually & arenot dependent on any other framework modules.

现在,考虑到这个简单的设计 - 我该如何设计我的单元测试.我打算使用 Test::More 来做所有的单元测试.我应该为每个模块编写单独的单元测试吗?有 25 个不同的模块属于这个框架.有什么建议吗?

Now, with that simple design in mind - how do I design my unit tests. I am planning to use Test::More to do all the unit tests. Should I write individual unit tests for each module? There are 25 different modules that belong to this framework. Any suggestions?

推荐答案

Z 的单元测试应该涵盖 Win32 功能.

Unit tests for Z should cover the Win32 functionality.

A 的单元测试应该涵盖 A 的功能,而这些功能在 Z 中没有涵盖.对 BCD 等重复.

Unit tests for A should cover the functionality of A that isn't covered in Z.Repeat for B, C, D, and so on.

如果您发现 CEG 正在做类似的事情并且您正在编写几乎相同的单元测试,那就是重构信号——将公共组件提取到更高级别(例如,模块CEG),然后离开并测试CEG 在它们的原始模块中.

If you find that C, E, and G are doing similar things and you are writing nearly identical unit tests, that is the signal to refactor -- extract common components up to a higher level (e.g., module CEG) and just leave and test the special parts of C, E, and G in their original modules.

这篇关于如何为同一发行版中的多个 Perl 模块设计单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:46