gpt4 book ai didi

java - 测试字符串 Junit

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:31:21 24 4
gpt4 key购买 nike

给定一个 toString 方法:

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

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

我如何使用 Junit 对其进行测试?

最佳答案

这是我的做法:

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());
}
}

关于java - 测试字符串 Junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5689795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com