Abhijith Prabhakar
Abhijith Prabhakar

Reputation: 1375

Emma coverage with Powermock

We have emma configured in our project which generates the coverage report. Whole setup was working fine until I introducted PowerMock to mock some of the static methods.

When I annotate a class with @RunWith(PowerMockRunner.class), emma tries to start coverage process again and throws up addressbind exception. I think maven surefire is forking a new JVM for different runner and emma tries to startup again on new JVM.

I tried with different options for surefire forkMode, but does not 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)

An idea on how to get around this? Any help greatly appretiated. Thanks

Upvotes: 4

Views: 2002

Answers (2)

Tema
Tema

Reputation: 4181

Bumping emma plugin version might work for plain java project but the latest android version of com.amazon.emma-droid still doesn't have this fix.

The problem appears only if you use at least two different JunitClassRunners (e.g. default one and @RunWith(PowerMockRunner.class)). I faced with the same issue when started to use RobolectricTestRunner. The workaround is to use the same JunitClassRunner for every test case in the module. E.g. use @RunWith(PowerMockRunner.class) even for simple JUnits w/o any PowerMock.

Upvotes: 0

Luigi Agosti
Luigi Agosti

Reputation: 925

If you don't specify the version of the emma plugin in to use maven will default to

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

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

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

the issue should disappear

Upvotes: 2

Related Questions