Emma's Spread With Powermock

We have emma configured in our project that generates a coverage report. The whole setup worked fine until I entered PowerMock to mock some static methods.

When I annotate a class with @RunWith (PowerMockRunner.class), emma tries to start the coverage process again and throws an addressbind exception. I think maven surefire is deploying a new JVM for different runners, and emma is trying to start a new JVM again.

I tried with various options for makefire forkMode, but that doesn't help. Running util.HttpClientFactoryTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.154 sec Running xxx.util.ServiceConnectorUtilTest EMMA: collecting runtime coverage data ... java.net.BindException: Address already in use: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)

The idea of ​​how to get around this? Any help greatly comprehended. Thanks

+4
source share
2 answers

If you do not specify the version of the emma plugin to use maven, the default will be

 <groupId>org.sonatype.maven.plugin</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0</version> 

If you specify the latest version 1.2 (or 1.1) in the assembly tag

 <build> <pluginManagement> <plugins> <plugin> <groupId>org.sonatype.maven.plugin</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0</version> </plugin> </plugins> </pluginManagement>... 

the problem should disappear

+2
source

The emma plugin version for plugins may work for a simple Java project, but the latest version of com.amazon.emma-droid still does not have this fix.

The problem only occurs if you use at least two different JunitClassRunners (for example, by default one and @RunWith (PowerMockRunner.class)). I encountered the same problem when I started using RobolectricTestRunner. The workaround is to use the same JunitClassRunner for each test case in the module. For instance. use @RunWith (PowerMockRunner.class) even for simple JUnits without any PowerMock.

0
source

Source: https://habr.com/ru/post/1399892/


All Articles