我正在尝试将 Presenter-First 方法用于一个新项目。我发现自己在下面的单元测试中。我是否通过在此测试中包含如此多的断言来利用糟糕的单元测试实践?如果是,是我的测试方法或presenter.setOverview 的实施有问题吗?换句话说,setOverview 方法是否应该调用 self.setSalesQty 而不是 self.view.setSalesQty?在这种情况下,我将对presenter.setSalesQty 进行单独的测试,而testSetOverview 测试将不再需要担心对此进行测试。
def testSetOverview(self):
# set up mock objects
p = PropertyMock()
type(self.mock_model).descriptions = p
self.mock_model.getData.side_effect = [5, 10]
self.mock_model.getDescription.side_effect = 'Description'
# get required variables
end = dt.date.today()
start = dt.date(year=end.year, month=1, day=1)
pn = 'abcd'
# call presenter method
self.presenter.setOverview(pn)
# test to make sure proper calls were made
model_getData_calls = [call(pn=pn, start=start, end=end,
data=self.mock_model.SHIPPED_QUANTITY),
call(pn=pn, start=start, end=end,
data=self.mock_model.PRICE_PAID)]
self.mock_model.getData.assert_has_calls(model_getData_calls, any_order=True)
assert self.mock_model.getDescription.called
self.mock_view.setSalesQty.assert_called_with(val=5)
self.mock_view.setSalesDols.assert_called_with(val=10)
self.mock_view.setDescription.assert_called_with(val='Description')