mercredi 23 septembre 2015

How do I test a money object method

This is the method, it is part of a trip planning application:

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

I have to make a jUnit test for it, this is what I have so far:

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

I have to submit my program to an online website which says that I am not testing the following lines of the beginning method:

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

Any help would be so greatly appreciated!!

Aucun commentaire:

Enregistrer un commentaire