[英]JUnit Test Case Keeps Failing - toString
Not quite sure why this is failing, worked fine on a previous class/test pair. 不太确定为什么会失败,因此在以前的课程/测试对中效果很好。
Test: 测试:
@Test
public void testToString() {
OrderLine o = new OrderLine("Tuna 4 pack", 399 , 2);
String toStr = o.toString();
assertTrue("The toString method should be in the standard convention format",
toStr.startsWith("OrderLine:[") &&
toStr.contains("=" + o.getId() + ", ") &&
toStr.contains("=" + o.getUnitPrice() + ", ") &&
toStr.endsWith("=" + o.getQuantity() + "]"));
}
Class Function: 类功能:
public String toString()
{
return ("OrderLine:[ ID = " + id +
", UnitPrice = " + unitPrice +
", Quantity = " + quantity +
"]");
}
Apologies if the answer to this is really obvious, its been grating me for some time and I don't exactly have any fellow students I can ask for help right now. 如果对此的答案确实很明显,我深表歉意,这已经困扰了我一段时间,而且我现在没有其他同学可以向我寻求帮助。
Thanks! 谢谢!
I had no idea that the spaces AFTER the equals mattered as my mind just seems to have read that they were irrelevant. 我不知道等号后的空格很重要,因为我的脑海似乎已经读到它们无关紧要。 I only put them there for the purpose of readability (my mistake I know)
我只是出于可读性目的将它们放在此处(我知道我的错误)
This is the rectified code oO 这是正确的代码oO
return ("OrderLine:[ID =" + id +
", UnitPrice =" + unitPrice +
", quantity =" + quantity +
"]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.