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?
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With