im moving c# -> java. need write tests using junit. in test need compare 2 strings see if match. have assert.assertequals, case sensitive. how can make case insensitive? need is:
"blabla".equals("blabla")
to return true.
so in c#, used have :
public static void areequal ( string expected, string actual, bool ignorecase, string message )
i going thru junit docs, can't seem find this.
i find hamcrest provides must better assertions default junit
asserts. hamcrest gives many many more options , provides better messages on failure. basic hamcrest
matchers built junit
, junit
has assertthat built in not totally new. see hamcrest.core
package in junit
api here. try isequalignoringcase this.
assertthat(mystring, isequalignoringcase.equaltoignoringcase(expected));
with static imports be
assertthat(mystring, equaltoignoringcase(expected));
if want fancy do:
assertthat(mystring, is(equaltoignoringcase(expected)));
one of advantages of failure state expected somestring someotherstring
. opposed expected true got false
when using asserttrue
.
Comments
Post a Comment