我是单元测试的新手,我想知道如果一个方法在内部调用它自己的公共方法来计算返回值会怎样,像下面这样:
public Integer getTotalBeforeSubscriptionDiscount() {
return getTotal() + getSubscriptionSavings()
}
我正在为它编写单元测试,我的问题是:在匹配结果和期望值时,是否应该使用特定的整数值,例如
Integer expected = 10;
Integer actual = obj.getTotalBeforeSubscription();
assertEquals(expected, actual);
或者,是否可以在运行时调用公共方法并计算期望值,就像以下:
Integer expected = obj.getTotal() + obj.getSubscriptionSavings();
assertEquals(expected, obj.getTotalBeforeSubscription());