AssertContains on strings in jUnit

前端 未结 10 1689
清酒与你
清酒与你 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

    Example (junit version- 4.13)

    import static org.assertj.core.api.Assertions.assertThat;
    import org.junit.Test;
    
    public class TestStr {
    
    @Test
    public void testThatStringIsContained(){
        String testStr = "hi,i am a test string";
        assertThat(testStr).contains("test");
     }
    
    }
    

提交回复
热议问题