[英]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.