AssertContains on strings in jUnit

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

Is there a nicer way to write in jUnit

String x = \"foo bar\";
Assert.assertTrue(x.contains(\"foo\"));
10条回答
  •  抹茶落季
    2020-12-22 21:57

    Another variant is

    Assert.assertThat(actual, new Matches(expectedRegex));
    

    Moreover in org.mockito.internal.matchers there are some other interesting matchers, like StartWith, Contains etc.

提交回复
热议问题