简体   繁体   中英

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. However, JaCoCo reports the method as uncovered, so I'm wondering what I might be missing.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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