我已经执行了Beck描述的“使用方法对象重构方法”重构。现在,我有一个带有“run()”方法和一堆成员函数的类,这些成员函数将计算分解为较小的单元。如何测试这些成员函数?
我的第一个想法是将我的单元测试基本上复制为“run()”方法(使用不同的初始化),但在每次调用成员函数之间添加断言来检查计算状态。 (我正在使用Python和unittest模块。)
我对在
我的第一个想法是将我的单元测试基本上复制为“run()”方法(使用不同的初始化),但在每次调用成员函数之间添加断言来检查计算状态。 (我正在使用Python和unittest模块。)
class Train:
def __init__(self, options, points):
self._options = options
self._points = points
# other initializations
def run(self):
self._setup_mappings_dict()
self._setup_train_and_estimation_sets()
if self._options.estimate_method == 'per_class':
self._setup_priors()
self._estimate_all_mappings()
self._save_mappings()
def _estimate_all_mappings():
# implementation, calls to methods in this class
#other method definitions
我对在
run()
方法的实现中调用不同方法之前和之后成员属性状态有期望值。我是否应该对这些“私有”属性进行断言?我不知道如何对这些方法进行单元测试。
另一个选择是我真的不应该测试这些属性。