Skip to content

Maven test fails to run moco server when using jacoco maven plugin 0.7.8 or newer #258

Description

@chenhengjie123

test case code:

import com.github.dreamhead.moco.Moco;
import com.github.dreamhead.moco.junit.MocoJunitRunner;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

public class BzdWithdrawHisServiceImplTest {
    @Rule
    public MocoJunitRunner runner = MocoJunitRunner.jsonHttpRunner(12306, Moco.pathResource("foo.json"));

    @Test
    public void  mockTest() throws IOException {
        HttpResponse httpResponse = Request.Get("http://localhost:12306").execute().returnResponse();
        System.out.println(httpResponse);
    }
}

error when running with mvn test:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.355 sec <<< FAILURE! - in com.ppmoney.feastful.fc.BzdWithdrawHisServiceImplTest
mockTest(com.ppmoney.feastful.fc.BzdWithdrawHisServiceImplTest)  Time elapsed: 0.012 sec  <<< ERROR!
java.lang.IllegalArgumentException: unknown field [$jacocoData]
	at com.ppmoney.feastful.fc.BzdWithdrawHisServiceImplTest.<init>(BzdWithdrawHisServiceImplTest.java:15)

configuration in pom.xml:

...
        <!-- https://mvnrepository.com/artifact/com.github.dreamhead/moco-junit -->
        <dependency>
            <groupId>com.github.dreamhead</groupId>
            <artifactId>moco-junit</artifactId>
            <version>0.12.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.github.dreamhead/moco-runner -->
        <dependency>
            <groupId>com.github.dreamhead</groupId>
            <artifactId>moco-runner</artifactId>
            <version>0.12.0</version>
        </dependency>
...
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

I have test with several versions, here is the result:

jacoco maven plugin version result
0.7.2.201409121644 success
0.7.7.201606060606 success
0.7.8 error
0.8.2 error

Almost the same as this issue: ERROR : Maven test fails to run moco server when using jacoco maven plugin.. Since it is closed, so I created this new issue instead.

Activity

  1. dreamhead commented on Jan 2, 2019

    @dreamhead
    Owner

    It seems jacoco inserts a field $jacocoData into Moco code which is supposed to be ignored by Jacoco. Could you please try to find some way to ignore it?

  2. chenhengjie123 commented on Jan 5, 2019

    @chenhengjie123
    Author

    It seems jacoco inserts a field $jacocoData into Moco code which is supposed to be ignored by Jacoco. Could you please try to find some way to ignore it?

    Do you know where I should try to modify so this error could be ignored? Since the stack trace just tell me the line of @test throws this error, but didn't tell the detail in MocoJunitRunner or jacoco, it's not easy for me to find where to modify.

  3. chenhengjie123 commented on Jan 5, 2019

    @chenhengjie123
    Author

    Also I created an issue for jacoco: jacoco/jacoco#816 .

  4. chenhengjie123 commented on Jan 5, 2019

    @chenhengjie123
    Author

    Jacoco has located the root cause and give a workaround method: jacoco/jacoco#816

    It seems moco need to change codes related to reflection to resolve this issue. @dreamhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions