Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing toString Junit

Given a toString method:

public String toString()
{
    String accountString;
    NumberFormat money = NumberFormat.getCurrencyInstance();

    accountString = cust.toString();
    accountString += " Current balance is " + money.format (balance);
    return accountString;
}

how i can test it with Junit?

like image 288
Édipo Féderle Avatar asked Apr 16 '11 21:04

Édipo Féderle


1 Answers

Here's how I'd do it:

public class AccountTest
{
    @Test
    public void testToString()
    {
        Account account = new Account(); // you didn't supply the object, so I guessed
        String expected = ""; // put the expected value here
        Assert.assertEquals(expected, account.toString());
    }
}
like image 140
duffymo Avatar answered Sep 21 '22 15:09

duffymo