By
using 'containsString' method, you can create a matcher that matches if the
examined string contains the specified String anywhere.
Ex
String
str = "Hello World";
assertThat("str
should contain 'World'", str, containsString("World"));
TestApp.java
package com.sample.model; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import org.junit.Test; public class TestApp { @Test public void containsString_testWithDiffScenarios() { String str = "Hello World"; assertThat("str should contain 'World'", str, containsString("World")); assertThat("str should contain 'Hello'", str, containsString("Hello")); assertThat("str should contain ' '", str, containsString(" ")); } }
No comments:
Post a Comment