Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

java - Getting a "no coverage data has been collected" message using EclEmma and Eclipse

I recently had this very annoying problem come out of nowhere. Running my unit tests with EclEmma coverage enabled causes the following dialog window to pop up from Eclipse:

enter image description here

For the search engines, it reads:

No coverage data has been collected during this coverage Session.
Please do not terminate the Java process manually from Eclipse.

No coverage information is provided for any of the classes in my project. Needless to say I am not terminating the Java process manually. To try and fix it I: reimported my project, upgraded Java, reinstalled Emma, restarted my Macbook Pro, made sure that temp filesystem space looked good, and 20 other things I'm forgetting right now.

I finally noticed that it was only a couple of my open source projects generating this error and decided to whittle down one of my tests. Here's the minimum test that reproduces the problem.

Test class I'm trying to get coverage on:

public class Foo {
    public void method() {
        System.out.println("hello");
    }
}

Here's the junit class which drives it:

public class EclEmmaFailureTest {
    @Test(timeout = 100000) // if you remove the timeout it works
    public void testStuff() {
        // this should cover Foo 100%
        new Foo().method();
        // if you comment this out stuff works
        org.apache.commons.logging.LogFactory.getLog(getClass());
    }
}

The commons-log Log reference in the test seems to break the coverage collection. I've posted a working repo at: https://github.com/j256/eclemma-failure

If you do any of the following, the problem goes away:

  • Comment out the LogFactory.getLog(getClass()) call.
  • Remove the junit @Test timeout field.
  • Downgrade Junit from 4.13.1 to 4.12.

I'm running Emma version 3.1.3 and my test program depends on commons-logging version 1.2.

I have a downgrade path that resolves this problem and gets me working again but Junit 4.12 has security issues. I'm curious if someone knows of the specific issue with junit or emma that is causing this.

Jacoco is also affected which isn't surprising. Here's my coverage report before upgrading to Junit 4.13.1 showing 80% coverage and here it is afterwards with no coverage information available showing 0%.

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No coverage data has been collected during this coverage Session. Please do not terminate the Java process manually from Eclipse.

This seems to be a Junit problem around threadgroups that was introduced in version 4.13. See this github discussion and see this pull request. When a timeout was set, it seems that Junit had been destroying the threadgroup to handle stuck threads issues which was not giving Eclemma a chance to write out the coverage information. They seem to have changed the thread-group to be daemon threads as a better way to handle this issue.

Seems like the only solution is going to have to wait for 4.13.2 to be released since versions before 4.13.1 suffer from a security issue.

Looks like shutdown hooks are not executed the same way in 4.13 as it used to happen in 4.12 and thus the coverage failure.

Thanks to the Eclemma mailing list for their help on this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...