JMockit Coverage including test class in coverage report #265

Judge40 opened this Issue Mar 3, 2016 · 2 comments


None yet

2 participants

Judge40 commented Mar 3, 2016

In a project which follows the Maven Standard Directory Layout a test class will be included in the coverage report.

Example directory layout:

When the coverage report is generated the below is seen in the report.

I tried setting 'coverage-srcDirs=src/main/java', but while that did have an effect the test class was still listed. I also tried excluding the filename pattern but saw the same result.

When multiple test classes exist it is still only a single test class which gets included in the report.

I tested with some earlier versions and it looks like the problem was first introduced in 1.20 but is still reproducible in 1.22.

In the test project ClassOne and ClassOneTest were actually very small classes, as below for reference, with only a single method/test respectively. Though this does not appear to be any factor as I've seen this in more complex projects originally.

public class ClassOne {
  public static ClassOne newClassOne() {
    return new ClassOne();
public class ClassOneTest {
  public void testNewClassOne_classOneInstance() {
    ClassOne classOne = ClassOne.newClassOne();
    Assert.assertThat(classOne, CoreMatchers.instanceOf(ClassOne.class));

There is a sample test suite in the JMockit repository, "samples/petclinic" (, which uses the standard Maven directory layout, and the coverage tool. Yet, I don't see test classes appearing in the HTML report.

So, I would need more information (in particular, a pom.xml file) so the problem can be reproduced.

Judge40 commented Mar 3, 2016

The project I noticed this in was actually a gradle project and the "ClassOne" test project was just a fresh Eclipse project from scratch.

Anyway, I tried your sample test suite and that all worked fine. So I did a bit of investigation and figured out what was going on.
If the "output" folder for "src/test/java/" does not end with "test-classes" then the test class will be listed in the report.
Changing my "ClassOne" test project to use the "test-classes" folder structure does cause the report to be output as expected.

Is it expected that the "test-classes" structure should always be used?

Note that I checked with 1.19 and that still works as expected regardless of the test classes output folder structure.
Also, it might be worth nothing that for me the test class shown in the report always seems to be the first test class to run (this is when running JUnit test through Eclipse).

@rliesenfeld rliesenfeld added the bug label Mar 5, 2016
@rliesenfeld rliesenfeld self-assigned this Mar 5, 2016
@rliesenfeld rliesenfeld added a commit that closed this issue Mar 5, 2016
@rliesenfeld rliesenfeld Coverage tool: fixed bug where the first test class executed from an …
…output directory not named "test-classes" (the Maven default) would show in the report; closes #265.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment