我目前正在学习python,为暑期的课程做准备,并且已经开始实现不同类型的堆和基于优先级的数据结构。在
我开始为这个项目编写一个单元测试套件,但是在创建一个只测试接口而忽略实际实现的通用单元测试时遇到了困难。在
我想知道是否有可能做这样的事。。在
suite = HeapTestSuite(BinaryHeap())
suite.run()
suite = HeapTestSuite(BinomialHeap())
suite.run()
我现在所做的只是感觉。。。错误(多重继承?确认!)。。在
^{pr2}$
Tags:
为什么不为要测试的类使用别名呢?您可以编写引用伪
HeapImpl
类的测试类,然后在每次测试运行之前为其分配特定的实现:只要它们符合您在测试套件中使用的接口,这应该可以正常工作。另外,您可以方便地测试任意多个实现,只需将它们添加到
heaps
列表中即可。在我个人更喜欢这种东西。我会这样写:
我不认为上述模式是可怕的,但多重继承肯定是不可取的。在
我想你不能让TestHeap成为TestCase的一个子类,是因为它将自动被提取并作为test运行,而不知道它需要被子类化。在
我用另外两种方法来解决这个问题:
__test__ = False
设置为基类。(见Testify)相关问题 更多 >
编程相关推荐