package com.leopard.spring;import java.time.LocalTime;import org.springframework.stereotype.Service;@Servicepublic class MessageBean {public String getMessage() { return "Button was clicked at " + LocalTime.now(); }}
1 回答
森林海
TA贡献2011条经验 获得超2个赞
这个类没有太多要测试的。您唯一可以测试的是它返回一个字符串,并且它与消息格式匹配。显然你无法测试你将获得的确切时间,但你可以期望它以消息开头:
@Test
public void testGetMessage() {
String expectedMessagePrefix = "Button was clicked at ";
String message = testedClass.getMessage();
assertTrue("did not get the expected message", message.startsWith(expectedMessagePrefix));
}
添加回答
举报
0/150
提交
取消