return "Button was clicked at " + LocalTime.now();
}
}
弑天下
浏览 131回答 1
1回答
森林海
这个类没有太多要测试的。您唯一可以测试的是它返回一个字符串,并且它与消息格式匹配。显然你无法测试你将获得的确切时间,但你可以期望它以消息开头:@Testpublic void testGetMessage() { String expectedMessagePrefix = "Button was clicked at "; String message = testedClass.getMessage(); assertTrue("did not get the expected message", message.startsWith(expectedMessagePrefix));}