Hamcrest:转储当前类型和值
Hamcrest: dump current type and value
我正在使用 Java 库 Hamcrest 编写测试,它不流畅 API 使得在复杂表达式演变时无法推断表达式类型,例如:
.andExpect(JsonUnitResultMatchers.json()
.matches(CoreMatchers.anyOf(CoreMatchers.allOf(
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
是否总有 TRUE 匹配器转储当前活动表达式的类型和值?喜欢:
.andExpect(JsonUnitResultMatchers.json()
.matches(CoreMatchers.anyOf(CoreMatchers.allOf(
Slf4jMatcher.logType(),
Slf4jMatcher.logTypeAndToString(),
ConsumerMatcher.apply(System.out::println),
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
我不喜欢使用调试器进入 Hamcrest 代码。深入研究某人的内部结构是徒劳的。
我想出了丑陋的:
.andExpect(JsonUnitResultMatchers.json()
.matches(Matchers.hasItem(CoreMatchers.allOf(
new BaseMatcher() {
@Override
public boolean matches(Object item) {
log.info("type: {}", item.getClass());
log.info("toString: {}", item.toString());
return true;
}
@Override
public void describeTo(Description description) {}
},
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
希望能有一些有趣的DSL...
我正在使用 Java 库 Hamcrest 编写测试,它不流畅 API 使得在复杂表达式演变时无法推断表达式类型,例如:
.andExpect(JsonUnitResultMatchers.json()
.matches(CoreMatchers.anyOf(CoreMatchers.allOf(
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
是否总有 TRUE 匹配器转储当前活动表达式的类型和值?喜欢:
.andExpect(JsonUnitResultMatchers.json()
.matches(CoreMatchers.anyOf(CoreMatchers.allOf(
Slf4jMatcher.logType(),
Slf4jMatcher.logTypeAndToString(),
ConsumerMatcher.apply(System.out::println),
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
我不喜欢使用调试器进入 Hamcrest 代码。深入研究某人的内部结构是徒劳的。
我想出了丑陋的:
.andExpect(JsonUnitResultMatchers.json()
.matches(Matchers.hasItem(CoreMatchers.allOf(
new BaseMatcher() {
@Override
public boolean matches(Object item) {
log.info("type: {}", item.getClass());
log.info("toString: {}", item.toString());
return true;
}
@Override
public void describeTo(Description description) {}
},
JsonMatchers.jsonPartEquals("id", "123"),
JsonMatchers.jsonPartEquals("name", "test")))))
希望能有一些有趣的DSL...