Repository navigation
Maven test fails to run moco server when using jacoco maven plugin 0.7.8 or newer #816
Description
Activity
@chenhengjie123 the list of dependencies is definitely incomplete:
BzdWithdrawHisServiceImplTest.java:[4,37] package org.apache.http.client.fluent does not existSo could you please attach zip with complete example without
...?- addedreproducer requiredFurther information is requestedFurther information is requested
on Jan 5, 2019 @chenhengjie123 the list of dependencies is definitely incomplete:
BzdWithdrawHisServiceImplTest.java:[4,37] package org.apache.http.client.fluent does not existSo could you please attach zip with complete example without
...?I have just uploaded the simplest project on https://github.com/chenhengjie123/ReproduceJacocoWithMoco. It can reproduce this issue.
And it shows different stack trace:
java.lang.IllegalArgumentException: unknown field [$jacocoData] at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.createResponseHandler(DynamicResponseHandlerFactory.java:116) at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.access$000(DynamicResponseHandlerFactory.java:37) at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory$1.apply(DynamicResponseHandlerFactory.java:70) at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory$1.apply(DynamicResponseHandlerFactory.java:65) at com.google.common.collect.Iterators$7.transform(Iterators.java:750) at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47) at com.google.common.collect.Iterators.size(Iterators.java:198) at com.google.common.collect.Iterables.size(Iterables.java:106) at com.google.common.collect.FluentIterable.size(FluentIterable.java:342) at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.getResponseHandler(DynamicResponseHandlerFactory.java:53) at com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.createResponseHandler(DynamicResponseHandlerFactory.java:49) at com.github.dreamhead.moco.parser.model.ResponseSetting.getResponseHandler(ResponseSetting.java:62) at com.github.dreamhead.moco.parser.model.SessionSetting.getResponseHandler(SessionSetting.java:66) at com.github.dreamhead.moco.parser.model.SessionSetting.bindToSession(SessionSetting.java:111) at com.github.dreamhead.moco.parser.model.SessionSetting.bindTo(SessionSetting.java:78) at com.github.dreamhead.moco.parser.model.SessionSetting.newHttpServer(SessionSetting.java:144) at com.github.dreamhead.moco.parser.HttpServerParser.createServer(HttpServerParser.java:23) at com.github.dreamhead.moco.parser.HttpServerParser.createServer(HttpServerParser.java:12) at com.github.dreamhead.moco.parser.BaseParser.parseServer(BaseParser.java:19) at com.github.dreamhead.moco.MocoJsonRunner.parseHttpServer(MocoJsonRunner.java:60) at com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer(MocoJsonRunner.java:21) at com.github.dreamhead.moco.junit.MocoJunitRunner.jsonHttpRunner(MocoJunitRunner.java:37) at demo.TestForReproduceMocoWithJacoco.<init>(TestForReproduceMocoWithJacoco.java:14)whose most relevant part is -
DynamicResponseHandlerFactory.java:49, three lines above there is call ofgetFieldsand two lines above there is call ofisValidFilterthat filtersfinalfields, but doesn't not filter outsyntheticfields, whereas should - please read https://www.jacoco.org/jacoco/trunk/doc/faq.html :My code uses reflection. Why does it fail when I execute it with JaCoCo?
To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic.
Please change your code to ignore synthetic members. This is a good practice anyways as also the Java compiler creates synthetic members in certain situation.
JaCoCo <=0.7.7 works, because in addition to field being
synthetic, it was also incorrectly alwaysfinal- see #434 that was fixed in 0.7.8.
As a workaround seems possible to exclude classes from instrumentation as following:
<execution> <goals> <goal>prepare-agent</goal> </goals> + <configuration> + <excludes>com/github/dreamhead/moco/*</excludes> + </configuration> </execution>with and without update to latest
- <jacoco.maven.plugin.version>0.7.8</jacoco.maven.plugin.version> + <jacoco.maven.plugin.version>0.8.2</jacoco.maven.plugin.version>
- addeddeclined: otherproject 👽This issue should be reported to other projectThis issue should be reported to other projectand removedreproducer requiredFurther information is requestedFurther information is requested
on Jan 5, 2019 OK,I got it. The trace is different maybe cause by the origin project has other configs. Since it's a company project, I could not share the whole project, so I create this new project instead.
Thanks a lot!
- locked as resolved and limited conversation to collaborators
on May 8, 2019
This is a issue tracker. Please use our mailing list for general questions:
https://groups.google.com/forum/?fromgroups=#!forum/jacoco
Also check FAQ before opening an issue: http://www.jacoco.org/jacoco/trunk/doc/faq.html
Steps to reproduce
test case code:
configuration in pom.xml:
error occurs when running
mvn testto run tests with jacoco.JaCoCo version: multiple, mentioned in Actual behaviour
Operating system: occurs on mac os 10.14 and windows 7
Tool integration: Maven/Ant/API/Other: maven
Expected behaviour
mvn test could run well
Actual behaviour
when running mvn test, error occurs like below: