How to consolidate scoverage of 2 jars

37 views
Skip to first unread message

surya.m...@gmail.com

unread,
May 16, 2019, 5:58:53 PM5/16/19
to Scala code coverage tool
I have 2 jars and calling few methods of 1st jar in 2nd jar. When I try to run scoverage of 2nd jar, it does not show me coverage of 1st jar. How to see coverage of all jars consolidated in a single report?

Grzegorz Slowikowski

unread,
May 22, 2019, 2:40:18 PM5/22/19
to Surya Munigoti, Scala code coverage tool
Hi
If you have only jars, you cannot measure coverage. You need to compile sources with scoverage to instrument classes. You can measure coverage only for instrumented classes or jars containing instrumented classes.
From your short description I don't know, what is your setup.

Regards
Grzegorz

czw., 16 maj 2019 o 23:58 <surya.m...@gmail.com> napisał(a):
I have 2 jars and calling few methods of 1st jar in 2nd jar. When I try to run scoverage of 2nd jar, it does not show me coverage of 1st jar. How to see coverage of all jars consolidated in a single report?

--
Scoverage, Scala code coverage tool
Github : https://github.com/scoverage
Discussion : https://groups.google.com/group/scala-code-coverage-tool
---
You received this message because you are subscribed to the Google Groups "Scala code coverage tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-code-coverag...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-code-coverage-tool/7a628647-e7c8-4ea6-8af5-6f5183f22a73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

surya.m...@gmail.com

unread,
May 23, 2019, 1:01:01 PM5/23/19
to Scala code coverage tool
Hi Grzegorz,
Please find below the details.

I am building spark-coverage.jar instrumented jar and included the same while submitting spark-coverage-test.jar using below spark-submit command on a stand alone Spark cluster. Please let me know how to get scoverage report generated for all the objects in both the jars and location of the coverage report. Please let me know if you need any additional details.

spark-submit --master local --deploy-mode client --jars D:\HDI\POCs\spark-master\sql\core\target\scoverage-spark-sql_2.12-3.0.0-SNAPSHOT.jar --class com.spark.scenario.Hello D:\HDI\POCs\spark-coverage-test\target\spark-coverage-test-0.0.1-SNAPSHOT.jar

Below is the object in spark-coverage.jar:

package com.spark.hellocoverage

object HelloWorld {
  def sayHello(): String = {
    "Hello"
  }
  def sayHelloAgain(): String = {
    "Hello Again"
  }
}

pom.xml
-----------------------
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.spark.test</groupId>
  <artifactId>spark-coverage</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spark-coverage</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <scala.version>2.12.8</scala.version>
    <spark.version>2.4.0</spark.version>
    <spark.core>2.12</spark.core>
    <scala.plugin.version>3.2.2</scala.plugin.version>
    <scoverage.plugin.version>1.4.0-M5</scoverage.plugin.version>
    <project-info-reports.plugin.version>3.0.0</project-info-reports.plugin.version>
    <!-- <skipTests>true</skipTests> -->
  </properties>
  <dependencies>
<dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version> <!-- 2.11.12 -->
    <scope>provided</scope> 
    </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_2.12</artifactId>
    <version>3.2.0-SNAP10</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>2.0.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.scalacheck</groupId>
    <artifactId>scalacheck_2.12</artifactId>
    <version>1.14.0</version>
    <scope>test</scope>
</dependency>

  </dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
<goal>add-source</goal>
</goals>
</execution>
</executions>
</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <finalName>${project.artifactId}-${project.version}</finalName>
<!--                     <finalName>uber-${project.artifactId}-${project.version}</finalName> -->
                </configuration>
            </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\AdoptOpenJDK\jdk-8.0.202.08\bin\javac.exe</executable>
</configuration>
</plugin>
            <plugin>
                <groupId>org.scoverage</groupId>
                <artifactId>scoverage-maven-plugin</artifactId>
                <version>${scoverage.plugin.version}</version>
<configuration>
<!-- <scalacPluginVersion>1.3.0</scalacPluginVersion> -->
                <minimumCoverage>0</minimumCoverage>
                <failOnMinimumCoverage>true</failOnMinimumCoverage>
               <!--  <additionalForkedProjectProperties>skipTests=false</additionalForkedProjectProperties> -->
            </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>report</goal> <!-- or integration-check -->
                        </goals>
                    </execution>
                </executions>
             </plugin>
<plugin>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest-maven-plugin</artifactId>
  <version>1.0</version>
    <configuration>
    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
    <junitxml>.</junitxml>
    <filereports>WDF TestSuite.txt</filereports>
  </configuration> 
    <executions>
    <execution>
      <id>test</id>
      <goals>
        <goal>test</goal>
      </goals>
    </execution>
  </executions>
</plugin>
</plugins>
</build>
<reporting>
        <plugins>
            <plugin>
                <groupId>org.scoverage</groupId>
                <artifactId>scoverage-maven-plugin</artifactId>
                <version>${scoverage.plugin.version}</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                            <!-- or <report>integration-report</report> -->
                            <!-- or <report>report-only</report> -->
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
  </reporting>
</project>


Below is the object in spark-coverage-test.jar:

object Hello {
   def main(args: Array[String]): Unit = {
    
/*      var logger = Logger.getRootLogger
      logger.setLevel(Level.ERROR)
      Logger.getLogger("org").setLevel(Level.OFF);
      Logger.getLogger("akka").setLevel(Level.OFF);
      Logger.getLogger("com").setLevel(Level.OFF);*/
    
      
    val spark = SparkSession
                  .builder()
                  .config("spark.master", "local")
                  .getOrCreate()

      
    
    System.out.println("####################### Hi Method: "+hi())  
  }

  def sayHello(): String = {
    "Hello"
  }
  
  def hi(): String = {
    com.spark.hellocoverage.HelloWorld.sayHelloAgain()  
  }

}

pom.xml:

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sparkcoverage.test</groupId>
  <artifactId>spark-coverage-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spark-coverage-test</name>

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <scala.version>2.12.8</scala.version>
    <spark.version>2.4.3</spark.version>
    <spark.core>2.12</spark.core>
    <scala.plugin.version>3.2.2</scala.plugin.version>
    <scoverage.plugin.version>1.3.0</scoverage.plugin.version>
    <project-info-reports.plugin.version>3.0.0</project-info-reports.plugin.version>
   <!--  <skipTests>true</skipTests> -->
    <scoverage.scalacPluginVersion>1.3.0</scoverage.scalacPluginVersion>
    <scoverage.aggregate>true</scoverage.aggregate>
  </properties>
  <dependencies>
<dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version> <!-- 2.11.12 -->
    <scope>provided</scope> 
    </dependency>
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_${spark.core}</artifactId>
    <version>${spark.version}</version>
      <scope>provided</scope>
</dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_${spark.core}</artifactId>
      <version>${spark.version}</version>
        <scope>provided</scope>
    </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_2.12</artifactId>
    <version>3.2.0-SNAP10</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest-maven-plugin</artifactId>
    <version>2.0.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.scalacheck</groupId>
    <artifactId>scalacheck_2.12</artifactId>
    <version>1.14.0</version>
    <scope>test</scope>
</dependency>
<!--         <dependency>
               <groupId>org.apache.spark</groupId>
               <artifactId>spark-catalyst_2.12</artifactId>
               <version>2.4.3</version>
               <scope>test</scope>
        </dependency> -->
<dependency>
    <groupId>org.scoverage</groupId>
    <artifactId>scalac-scoverage-runtime_2.10</artifactId>
    <version>1.3.0</version>
    <!-- <scope>provided</scope> -->
</dependency>
  </dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
<goal>add-source</goal>
</goals>
</execution>
</executions>
</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <finalName>${project.artifactId}-${project.version}</finalName>
<!--                     <finalName>uber-${project.artifactId}-${project.version}</finalName> -->
                </configuration>
            </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\AdoptOpenJDK\jdk-8.0.202.08\bin\javac.exe</executable>
</configuration>
</plugin>
            <plugin>
                <groupId>org.scoverage</groupId>
                <artifactId>scoverage-maven-plugin</artifactId>
                <version>${scoverage.plugin.version}</version>
<configuration>
<!-- <scalacPluginVersion>1.3.0</scalacPluginVersion> -->
                <minimumCoverage>0</minimumCoverage>
                <failOnMinimumCoverage>true</failOnMinimumCoverage>
                <aggregate>true</aggregate>
                <!-- <additionalForkedProjectProperties>skipTests=false</additionalForkedProjectProperties> -->
            </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-report</goal> <!-- or integration-check -->
                        </goals>
                    </execution>
                </executions>
             </plugin>
<plugin>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest-maven-plugin</artifactId>
  <version>2.0.0</version>
    <configuration>
    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
    <junitxml>.</junitxml>
    <filereports>WDF TestSuite.txt</filereports>
  </configuration> 
    <executions>
    <execution>
      <id>test</id>
      <goals>
        <goal>test</goal>
      </goals>
    </execution>
  </executions>
</plugin>
</plugins>
</build>
<reporting>
        <plugins>
            <plugin>
                <groupId>org.scoverage</groupId>
                <artifactId>scoverage-maven-plugin</artifactId>
                <version>${scoverage.plugin.version}</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <!-- <report>report</report> -->
                            <report>integration-report</report>
                            <!-- or <report>report-only</report> -->
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
  </reporting>
</project>


On Wednesday, May 22, 2019 at 11:40:18 AM UTC-7, Grzegorz Slowikowski wrote:
Hi
If you have only jars, you cannot measure coverage. You need to compile sources with scoverage to instrument classes. You can measure coverage only for instrumented classes or jars containing instrumented classes.
From your short description I don't know, what is your setup.

Regards
Grzegorz

czw., 16 maj 2019 o 23:58 <surya....@gmail.com> napisał(a):
I have 2 jars and calling few methods of 1st jar in 2nd jar. When I try to run scoverage of 2nd jar, it does not show me coverage of 1st jar. How to see coverage of all jars consolidated in a single report?

--
Scoverage, Scala code coverage tool
Github : https://github.com/scoverage
Discussion : https://groups.google.com/group/scala-code-coverage-tool
---
You received this message because you are subscribed to the Google Groups "Scala code coverage tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-code-coverage-tool+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages