AssertContains on strings in jUnit

前端 未结 10 1633
清酒与你
清酒与你 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 22:09

    It's too late, but just to update I got it done with below syntax

    import org.hamcrest.core.StringContains;
    import org.junit.Assert;
    
    Assert.assertThat("this contains test", StringContains.containsString("test"));
    

提交回复
热议问题