基本前提是,如果被测字符串以点结尾,则检查预期的字符串是否以被测字符串开头(但没有点)。
下面的代码未经测试,您可能需要考虑null
字符串场景。
static final String DOTS = "...";
String actual = "The quick brown fox...";
String expected = "The quick brown fox jumps over the lazy dog";
public void testStringWithDots(String actual, String expected) {
if (actual.endsWith(DOTS)) {
String prefix = actual.substring(0, actual.length() - DOTS.length());
Assert.assertTrue("Strings are same up to dots", expected.startsWith(prefix);
} else {
Assert.assertEquals("Strings are same", expected, actual);
}
}