繁体   English   中英

使用@Autowired进行接口实现的JaCoCo代码覆盖

[英]JaCoCo code coverage on interface implementations using @Autowired

我为测试创建了一个包含默认方法的接口。 目前,它看起来像这样:

public interface CRUDTest<
        Controller extends ControllerCRUD<Model, DTO, Creation, Update, Service>,
        Service extends ServiceCRUD<Model, Creation, Update, ? extends GenericRepository<Model>>,
        Creation extends CreationDTO<Model>,
        Update extends UpdateDTO<Model>,
        DTO extends ModelDTO,
        Model extends GenericModel> {

  Controller getController();
  Service getService();
  ImageService getImageService();

  Creation generateCreationDTO();

  default void doStuff() {
    service().createFromDTO(generateCreationDTO());
    // ...
  }
}

然后,每个测试都通过以下方式实现此接口:

public class Implementation implements CRUDTest<ExampleController, ExampleService, ExampleCreationDTO, ExampleUpdateDTO, ExampleDTO, ExampleModel> {

  @Autowired @Getter private SongService service;

  @Autowired @Getter private SongController controller;

  @Autowired @Getter private ImageService imageService;


  @Test
  public void doStuff() {
    CRUDTest.super.doStuff();
  }
}

据我所知,我的服务中的“ createFromDTO”方法现在应该报告为JaCoCo所涵盖,并且在运行测试时显然会调用它。 但是,JaCoCo报告该方法未被发现,因此我想知道我可能会丢失什么。

我发现了问题! 我正在从事的项目遵循多模块结构,并且某些集成测试包括来自其他项目的方法。 因此,JaCoCo并未涵盖这些方法,但是通过谷歌搜索使我相信,有几种方法可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM