如何测试货币对象方法

时间:2015-09-24 00:49:44

标签: java unit-testing object methods junit

这是方法,它是旅行计划申请的一部分:

public Money totalCost() {
    Money total = new Money();
    for (int ii = 0; ii < componentCount; ii++) {
        total.add(components[ii].getCost());     
    }
    return total;
}

我必须为它做一个jUnit测试,这是我到目前为止所做的:

public void testTotalCost() {
    Money testTotal = new Money();
    Money expected = testTotal;
    Money actual = tripTest1.totalCost();
    assertEquals("Error: ", expected, actual);  
}

我必须将我的程序提交到一个在线网站,该网站说我没有测试开头方法的以下几行:

for (int ii = 0; ii < componentCount; ii++) {
    total.add(components[ii].getCost());  

任何帮助都会非常感激!!

0 个答案:

没有答案
相关问题