Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用@WebMvcTest连接千分尺_Java_Spring Boot_Junit_Resttemplate_Spring Micrometer - Fatal编程技术网

Java 如何使用@WebMvcTest连接千分尺

Java 如何使用@WebMvcTest连接千分尺,java,spring-boot,junit,resttemplate,spring-micrometer,Java,Spring Boot,Junit,Resttemplate,Spring Micrometer,我正在尝试测试SpringBoot2.3@Controller,它通过执行器/Prometheus使用@WebMvcTest进行度量。不幸的是,这在NPE中失败,可能是因为千分尺/普罗米修斯等级不在测试中 控制器执行以下操作: Counter.builder(COUNTER_STATUS) .description(DESCRIPTION_STATUS) .tags(TAG_ACCOUNT, String.valueOf(accountId), TAG_STATU

我正在尝试测试SpringBoot2.3
@Controller
,它通过执行器/Prometheus使用
@WebMvcTest
进行度量。不幸的是,这在NPE中失败,可能是因为千分尺/普罗米修斯等级不在测试中

控制器执行以下操作:

Counter.builder(COUNTER_STATUS)
        .description(DESCRIPTION_STATUS)
        .tags(TAG_ACCOUNT, String.valueOf(accountId), TAG_STATUS, String.valueOf(status))
        .register(registry)
        .increment();
测试已经完成

@ExtendWith(SpringExtension.class)
@ExtendWith(MockitoExtension.class)
@WebMvcTest(HerodotusController.class)

  @MockBean(MeterRegistry.class)
  private MeterRegistry meterRegistry;
如果在
计数器
的行中有一个NPE,则此操作失败。。。;我相信这是因为在测试运行时没有该接口的实现(在运行时它是由
io.milomer:milomer registry prometheus
实现的)


如何在测试中实现测微计接口,使其通过测试?

问题在于模拟的
计量注册表

NPE发生在这里:

public Counter register(MeterRegistry registry) {
  return registry.counter(new Meter.Id(name, tags, baseUnit, description, Type.COUNTER));
}
解决方案是不模拟计量注册,而是通过

@TestConfiguration
static class AdditionalConfig {
  @Bean
  public MeterRegistry registry() {
    return new SimpleMeterRegistry();
  }
}