简体   繁体   English

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

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

I've created an interface for my tests which contains default methods. 我为测试创建了一个包含默认方法的接口。 At the moment, it looks something like this: 目前,它看起来像这样:

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());
    // ...
  }
}

Then, each test implements this interface in the following way: 然后,每个测试都通过以下方式实现此接口:

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();
  }
}

As far as I can tell, the "createFromDTO" method in my service should now be reported as covered by JaCoCo, and it is obviously called when running the tests. 据我所知,我的服务中的“ createFromDTO”方法现在应该报告为JaCoCo所涵盖,并且在运行测试时显然会调用它。 However, JaCoCo reports the method as uncovered, so I'm wondering what I might be missing. 但是,JaCoCo报告该方法未被发现,因此我想知道我可能会丢失什么。

I found the issue! 我发现了问题! The project I'm working on follows a multimodule structure, and some of the integration tests included methods from a different project. 我正在从事的项目遵循多模块结构,并且某些集成测试包括来自其他项目的方法。 These methods were thus not covered by JaCoCo, but some googling leads me to believe there's several ways to fix this. 因此,JaCoCo并未涵盖这些方法,但是通过谷歌搜索使我相信,有几种方法可以解决此问题。

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

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