I have a test, I want to assert its result:
assertThat(cofmanString, new IsEqualIgnoringCase(FileUtils.readFileToString(new File("/Users/myFile.txt"))));
in Intellij I see the strings are identical including tabs and newlines
actual:
but the test fails like this:
which hamcrest matcher can i use to compare the strings and succeed?
You can use this:
assertThat(cofmanString, equalToIgnoringWhiteSpace(FileUtils.readFileToString(
new File("/Users/myFile.txt")).toLowerCase()));
You can see more for IsEqualIgnoringWhiteSpace here
There is no "ignore tabs" option, but you can just remove all tabs before comparing by applying .replace("\\t", "")
to each term:
assertThat(cofmanString.replace("\t", ""), new IsEqualIgnoringCase(
FileUtils.readFileToString(new File("/Users/myFile.txt"))).replace("\t", ""));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.