gpt4 book ai didi

java - JUnit 检查新 API 是否包含枚举

转载 作者:行者123 更新时间:2023-12-02 10:09:08 24 4
gpt4 key购买 nike

我是单元测试新手,我想检查新 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com