naomimyselfandi
naomimyselfandi

Reputation: 56

IntelliJ coverage report is inconsistent

I've been having a very strange problem with IntelliJ's code coverage report, which I haven't been able to find mentioned anywhere else. For a few of the classes in one package, if I run the corresponding tests manually, the coverage report shows 100% coverage for those classes; however, if I run the tests for the entire package, the coverage for those classes is significantly lower (but not 0%), even though the same tests are shown as having been run. (e.g. if I run com.example.wtf.FooTest, I see 100% coverage for com.example.wtf.Foo, but if I run the tests for com.example.wtf, I see 47% coverage for com.example.wtf.Foo, even though com.example.wtf.FooTest was properly run.) mvn clean, deleting the run configurations, and even manually copying the test class (e.g. copying com.example.wtf.FooTest to com.example.wtf.FooTest2) haven't done anything to resolve the issue.

Also, I'm not sure if this is related or not, but the branch coverage has been somewhat suspect; seemingly random lines have reported very high branch counts (e.g. return this; being reported as having 8/10 branches covered). I noticed both issues during a somewhat complex refactoring, which makes me suspect they're related, but it could be coincidence.

The project is using Maven, Java 23 (w/o preview features), and JUnit5. I'm not using any particularly exotic functionality; there are a few uses of MockitoExtension, but no other extensions, and all of the @ParameterizedTests use standard test sources. I'm really at a loss for what may be throwing off the coverage report like this.


For context, here's one of the classes with extraneous details (mostly names) removed:

@Service
class FooFactory extends MemberHandler implements Supplier<Foo> {

    // superclass implements InvocationHandler and autowires a few dependencies

    private final Foo proxy = createProxy();

    @Override
    public Foo get() {
        return proxy;
    }

    private Foo createProxy() {
        return (Foo) newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, this);
    }

}

When I run FooHandlerTest, everything is marked as covered, but when I run the tests for the package, only createProxy is marked as covered.

Another class has a setup like this:

@Service
class BarService implements Function<List<Foo>, Bar> {

    Bar apply(Foo... foos) {
        return apply(List.of(foos));
    }

    @Override
    public Bar apply(List<Foo> foos) {
        // ...
    }

}

When I run the package tests, the first method is marked as covered and the second isn't, which doesn't make sense; again, running BarServiceTest in isolation shows the correct coverage.

Upvotes: 0

Views: 31

Answers (0)

Related Questions