我是单元测试新手,我想检查新 API 是否包含指定的枚举。我应该更改什么而不是 is(true)
因为现在它返回 boolean 值但我需要列表?
枚举类:
public enum SupportingColor
{
GREEN,
BLACK
}
支持颜色方法:
public List<SupportingColor> supportingColor() {
return configuration.supportingColor();
}
测试用例:
@Test
public void NEW_API_hasBlack() {
ApiVersionFeatures features = ApiVersionFeatures.getByApiVersion(ApiVersion.NEW_API);
assertThat(features.supportingColor(), is(true));
}
最佳答案
您可以使用
assertThat(actual, Matchers.contains(SupportingColor.BLACK, SupportingColor.GREEN));
[Matchers][1]
中还有其他 contains
变体。浏览 API 文档
关于java - JUnit 检查新 API 是否包含枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55121647/