首页 > 解决方案 > Hamcrest:file1 或者 file2 存在

问题描述

我目前将我的测试从 AsserJ 重构为 hamcrest 库。但是有一种说法是我不能迁移到 hamcrest。

tmp1 和 tmp2 在文件系统中包含两个路径。我需要验证 tmp1 或 tmp2 是否存在,但不能同时存在。当前的断言是

assertTrue(new File(tmp1).exists() ^ new File(tmp2).exists());

什么是等效的 hamcrest 测试?

标签: tddhamcrest

解决方案


 assertThat(new File(tmp1).exists() ^ new File(tmp2).exists(), is(true));

推荐阅读