2017-07-13 8 views
1

私がテストを持って、私はその結果を主張したい:タブを無視してテキストを比較するhamcrestの使い方は?

のIntelliJで
assertThat(cofmanString, new IsEqualIgnoringCase(FileUtils.readFileToString(new File("/Users/myFile.txt")))); 

私は文字列がタブ、改行

実際含めて同一であり、以下を参照してください期待

enter image description here

enter image description here

ただし、テストは失敗しますこの:hamcrestマッチャが、私は文字列を比較し、成功するために使用することができます

enter image description here

答えて

0

そこには「タブを無視する」オプションはありませんが、あなただけの各用語に.replace("\t", "")を適用することにより、比較する前にすべてのタブを削除することができます。

assertThat(cofmanString.replace("\t", ""), new IsEqualIgnoringCase(
    FileUtils.readFileToString(new File("/Users/myFile.txt"))).replace("\t", "")); 
4

あなたがこれを使用することができます:

assertThat(cofmanString, equalToIgnoringWhiteSpace(FileUtils.readFileToString(
new File("/Users/myFile.txt")).toLowerCase())); 

することができますIsEqualIgnoringWhiteSpaceの詳細を見るhere

関連する問題