0

这是 Junit5 反复出现的挑战@ParametrizedTest......

我想将以下表达式(显然是一个字符串)传递给我的断言,但是字符串参数expectedTemplate保持为一个字符串,并且它不像我在 Bash 中所期望的那样“扩展”(执行)......很难制定我希望从这段代码中实现的目标会更清晰:

@ParameterizedTest
@CsvSource({" '/path/to/pool.Json', '/path/to/service.Json', 'Constants.GENERIC_TEMPLATE'"}
void testTemplateNameIsLoadedCorrectly(String poolJson, String serviceJson, String expectedTemplate) {
  Pool pool = testSupport.getObject(poolJson, Pool.class);
  ServiceDescriptor service = testSupport.getObject(serviceJson, ServiceDescriptor.class);
  ...
  ...

  assertEquals(expectedTemplateName, service.getUserRevokeTemplate());
}

请注意

  • Constants是一个持有常量值的类,主要由 JUnit 测试使用。
  • tesSupport是一个内部帮助器工厂类,它从提供的 JSON 文件构造给定对象。

运行测试时失败:

org.opentest4j.AssertionFailedError: 
Expected :Constants.GENERIC_TEMPLATE
Actual   :generic-user-revocation-email.ftl

因为常量GENERIC_TEMPLATEin的值Constants不是作为表达式处理:Constants.GENERIC_TEMPLATE而是保持为 String :-(

4

0 回答 0