使用用于 Java 的 hamcrest 库,这是一种很好阅读的方式来做相反的事情:
assertThat(someCollection, hasItem(someItem))
我想确保someCollection
不包含项目someItem
否定hasItem
断言
assertThat(someCollection, not(hasItem(someItem)))
如果你需要断言一个数组,同样的逻辑使用not(hasItemInArray())
final String[] availableIds = {"123", "321"};
final String userId = "333";
softAssert.assertThat("Id not found", availableIds, not(hasItemInArray(userId)));
softAssert.assertAll();