jeudi 9 août 2018

JaCoCo code coverage on interface implementations using @Autowired

I've recently started work on a project which uses reflection to test several services, all of them implementing a common interface.

Basically, my test looks something like this:

public ExampleTest {

    @Autowired
    List<ServiceInterface> services;

    @Test
    public void example() {
        for (ServiceInterface service: services) {
            service.doSomething();
        }
    }
}

The problem is that JaCoCo does not seem to detect each service's implementation of doSomething() as being called, so they all appear as uncovered by tests. My guess would be that it can't tell the particular class for each service, but I'm at a loss as to how to fix it.

Aucun commentaire:

Enregistrer un commentaire