eclemma icon indicating copy to clipboard operation
eclemma copied to clipboard

Support coverage for spawned (Java) child processes (Feature request)

Open nlang5555 opened this issue 10 years ago • 1 comments

The desired use case is to collect coverage when JUnit testing a Java 'main' class. Typically, such a 'main' class is tested by spawning it in its own process during the JUnit test. A naive process execution (e.g. exec 'java acme.Main') cannot collect coverage, since it does not load the JaCoCo agent. So, it is understood that at least some JaCoCo argument must be passed in the exec line. However, it is hard to see how that argument can be properly constructed from within the JUnit test. At least the following is unknown/hard to obtain:

  • Exact classpath of the jacoco agent
  • Port of the Jacoco server
  • Sessionid to be used

Ideally, the Emma plugin would make the required JaCoCo argument available as a 'defined' property, e.g. 'jacoco.jvm.arg', available for application during the JUnit test. In this way, child processes can easily be constructed with the appropriate JaCoco configuration argument.

nlang5555 avatar Mar 29 '15 15:03 nlang5555

Some random remarks:

  • The agent parameter could be obtained from the RuntimeMXBean:

    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); System.out.println(runtimeMXBean.getInputArguments());

  • The EclEmma plug-in currently accepts a single connection per launch only. For multiple connections we have to clarify whether they create different sessions or get merged into the same session. If a dump is requested from a running VM should the child processes also considered?

  • As a workaround you could configure a file output location for the child processes and import/merge the created exec file.

marchof avatar Mar 30 '15 05:03 marchof