【问题标题】:Check the value of an option in a unit test for Picocli在 Picocli 的单元测试中检查选项的值
【发布时间】:2021-11-05 11:55:06
【问题描述】:

在使用picocli 的实用程序的单元测试中,我想断言 picocli 为选项分配了正确的值。如何在单元测试中获取与选项关联的值?

这是当前版本的单元测试:

@Test
void callWithOptionForSuffix() {
    NextMajorSubcommand command = new NextMajorSubcommand();
    CommandLine cmdline = new CommandLine(command);

    ParseResult parseResult = cmdline.parseArgs("--suffix", "DELTA", "4.5.6");

    assertThat(parseResult.hasMatchedPositional(0)).isTrue();
    assertThat(parseResult.matchedOptions()).isNotEmpty();
    assertThat(parseResult.matchedOption("--suffix").isOption());
}

【问题讨论】:

    标签: java unit-testing picocli


    【解决方案1】:

    Picocli 提供getValue() 方法来获取选项的解析值。

    assertThat(parseResult.matchedOption("--suffix").String>getValue())
        .hasValue("DELTA");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-12
      • 2020-04-04
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      相关资源
      最近更新 更多