想要一个JUnitMatchers AssertThat来测试字符串包含3个或更多子字符串(当前使用assertThat ...和...和....) [英] Want a JUnitMatchers AssertThat to test string contains 3 or more sub strings (currently using assertThat ... both ... and ....)

查看:114
本文介绍了想要一个JUnitMatchers AssertThat来测试字符串包含3个或更多子字符串(当前使用assertThat ...和...和....)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import static org.junit.matchers.JUnitMatchers.both;
import static org.junit.matchers.JUnitMatchers.containsString;

现在我检查它是否包含foo和bar,如下所示...

Now I check it contains foo and bar as below ...

        Assert.assertThat(text,
            both(containsString("foo")).
            and(containsString("bar")));

最干净的测试方法还应检查它是否包含3个或更多字符串,例如'foo','bar'和'baz'吗?

What is cleanest way to test also check it contains 3 or more strings e.g. 'foo', 'bar' and 'baz' ?

推荐答案

使用

这篇关于想要一个JUnitMatchers AssertThat来测试字符串包含3个或更多子字符串(当前使用assertThat ...和...和....)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆