4
votes

I would like to see the test coverage for IT tests run with Arquillian. I ran into this extension: https://github.com/arquillian/arquillian-extension-jacoco

What I dont understand is why CoverageBean class tested by JacocoInegrationTestCase is not visible in the reports. Thats what I would expect.
Can somebody provide the example project, with 1 integration test running on Arquillian and tested class for which the test coverage report is generated, please?
Thanks

@RunWith(Arquillian.class)
public class JacocoInegrationTestCase
{
@Deployment
public static JavaArchive createDeployment() throws Exception
{
   return ShrinkWrap.create(JavaArchive.class, "test.jar")
                 .addClasses(CoverageBean.class, JacocoInegrationTestCase.class);
}
@EJB
private CoverageBean bean;
@Test
public void shouldBeAbleToGenerateSomeTestCoverage() throws Exception
{
  Assert.assertNotNull(bean);    
  bean.test(true);

} }

@Stateless
public class CoverageBean
{
public void test(Boolean value) 
{
  String test = "test";
  if(value)
  {
     if(test.length() == 4)
     {
        long start = System.currentTimeMillis();
        test = String.valueOf(start);
     }
  } 
  else
  {
     long start = System.currentTimeMillis();
     test = String.valueOf(start);
  }

} }

 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
   <configuration>
      <skip>true</skip>
   </configuration>
<executions>
   <execution>
     <id>integration-tests</id>
     <phase>test</phase>
    <goals>
      <goal>test</goal>
   </goals>
<configuration>
   <environmentVariables>
      <JBOSS_HOME>${jbossHome}</JBOSS_HOME>
   </environmentVariables>
<skip>false</skip>
<includes>
    <include>org/jboss/arquillian/extension/jacoco/test/unit/ * </include>
         <include>org/jboss/arquillian/extension/jacoco/test/integration/ * </include>   
</includes>
</configuration>
</execution>

EDIT: I have also try this project (https://github.com/CSchulz/arquillian-jacoco-showcase), looks very promissing but it runs against the distribution verison of Wildfly.. But in my project we are running Arquillian tests agains the installed instance of JBOSS EAP 6, with database connection and other security configuration. Is anybody able to change it in order to use the installed (deployed) version of JBOSS? Thanks

2
Could you please post your config and the deployment? - LightGuard
Project can be donwloaded from the github. I updated my answer with few relevant code snippets. Stil wondering why the coverage its not calculated, eventhought the code is called. - troger19
An the Arquillian side, all you'd need to do is change the arquillian dependency to what you're already using in your project, and also change the Java EE version. You said your project is available in github, but you didn't add a link to it. - LightGuard

2 Answers

2
votes

This is the configuration that works for me. See if it helps you.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.plugin.maven.surefire}</version>
            <configuration>
                <failIfNoTests>false</failIfNoTests>
                <excludedGroups>org.jboss.arquillian.junit.Arquillian</excludedGroups>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${version.plugin.maven.failsafe}</version>
            <configuration>
                <groups>org.jboss.arquillian.junit.Arquillian</groups>
                <testFailureIgnore>false</testFailureIgnore>
                <systemPropertyVariables>
                    <arquillian.launch>jbossas-remote-7</arquillian.launch>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco-plugin.version}</version>
            <configuration>
                <includes>
                </includes>
                <excludes>
                    <exclude>.....</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-prepare-agent-integration</id>
                    <goals>
                        <goal>prepare-agent-integration</goal>
                    </goals>
                    <configuration>
                        <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                    </configuration>
                </execution>
                <execution>
                    <id>Create Unit Test Report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>Create Integration Test Report</id>
                    <goals>
                        <goal>report-integration</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
0
votes

Based on the info you've provided, it looks like you haven't executed the prepare-agent goal. You can see the full example in the README.