有没有一种更好的用jUnit编写的方法?
String x = "foo bar";
Assert.assertTrue(x.contains("foo"));
发布于 2009-07-07 13:05:52
如果你加上Hamcrest和JUnit4,你可以这样做:
String x = "foo bar";
Assert.assertThat(x, CoreMatchers.containsString("foo"));
使用一些静态导入,它看起来要好得多:
assertThat(x, containsString("foo"));
所需的静态导入将为:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
发布于 2012-12-08 20:05:34
尽可能使用fest assert 2.0编辑:assertj可能有更多断言(一个分支)
assertThat(x).contains("foo");
https://stackoverflow.com/questions/1092219
复制相似问题