AssertContains on strings in jUnit

前端 未结 10 1644
清酒与你
清酒与你 2020-12-22 21:09

Is there a nicer way to write in jUnit

String x = \"foo bar\";
Assert.assertTrue(x.contains(\"foo\"));
10条回答
  •  萌比男神i
    2020-12-22 21:49

    I've tried out many answers on this page, none really worked:

    • org.hamcrest.CoreMatchers.containsString does not compile, cannot resolve method.
    • JUnitMatchers.containsString is depricated (and refers to CoreMatchers.containsString).
    • org.hamcrest.Matchers.containsString: NoSuchMethodError

    So instead of writing readable code, I decided to use the simple and workable approach mentioned in the question instead.

    Hopefully another solution will come up.

提交回复
热议问题