项目设置与业务对象创建:从测试到部署的全流程指南
一、属性和方法测试装饰器
装饰器可看作是一个函数,它接受另一个函数作为参数,并在不实际修改被装饰函数的情况下,扩展或包装其功能。任何可调用对象,如函数、类的实例方法或类方法,都可作为装饰函数。在代码覆盖测试用例类中,定义了两个类方法 AddPropertyTesting 和 AddMethodTesting ,使用装饰器函数结构为被装饰的类添加新方法 testPropertyCoverage 和 testMethodCoverage 。
1.1 AddMethodTesting 方法详解
此方法首先检查自身是否为 ModuleCoverageTest 类的扩展成员,以确保处理的数据仅与源模块和测试模块相关:
@classmethod
def AddMethodTesting(cls, target):
if cls.__name__ == 'ModuleCoverageTest':
raise RuntimeError('ModuleCoverageTest should be extended '
'into a local test-case class, not used as one directly.')
if not cls._testModule:
raise AttributeErr
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



