用junit 4.12测试元素是否在列表中



我有下一个测试:

public void test() {
final File dir = new File("/workspaces/").getAbsoluteFile();
List<File> testList = object
.getList(dir, “string1, string2);
assertNotNull(testList);
int resultSize = testList.stream().filter(
target -> target.getPath().equals(“s”tring1) ||
target.getPath().contains("String2withTransformation"))
.collect(Collectors.toList()).size();
assertEquals(2, resultSize);
}

测试的想法是要过滤,如果调用getList方法后,我将与字符串参数,我将在testList中有这些字符串,第一个具有相同的值,第二个是String2withTransformation加上一些路径,因为我使用包含,但这个测试似乎有问题或不准确,我该如何改进它的任何想法?

谢谢!

我不确定我在跟随你,我肯定不能跟随你的代码(对不起,但你甚至测试什么列表?),但根据描述,你不想要这样的东西:

List<some-type> myList = ...... ;

Assert.assertTrue(myList.contains(some-value));

最新更新