chetanmeh commented on issue #3243: Collect test code coverage data
URL: 
https://github.com/apache/incubator-openwhisk/issues/3243#issuecomment-362995897
 
 
   ## How scoverage works
   
   Scoverage [gradle plugin][1] configures a [scala compiler plugin][2] which 
then instruments the source code and generates instrumented classes in 
`build/classes/scala/scoverage`. 
   
   It also generates a `build/scoverage/scoverage.coverage.xml` which is a db 
of source code instrumentation mapping
   
   ```xml
   <statements>
     <statement>
       
<source>/absolute/path/of/openwhisk/common/scala/src/main/scala/whisk/core/entity/EntityPath.scala</source>
       <package>whisk.core.entity</package>
       <class>EntityPath</class>
       <classType>Object</classType>
       <fullClassName>whisk.core.entity.EntityPath</fullClassName>
       <method>apply</method>
       
<path>/absolute/path/of/openwhisk/common/scala/src/main/scala/whisk/core/entity/EntityPath.scala
       </path>
       <id>3331</id>
       <start>5251</start>
       <end>5309</end>
       <line>149</line>
       
<description>scala.this.Predef.require(parts.!=(null).&amp;&amp;(parts.nonEmpty),
 &quot;path undefined&quot;)
       </description>
       <symbolName>scala.Predef.require</symbolName>
       <treeName>Apply</treeName>
       <branch>false</branch>
       <count>0</count>
       <ignored>false</ignored>
     </statement>
   ...
   </statements>
   ```
   
   The instrumented source looks like below (post decompile). Here call is 
being made to `scoverage.Invoker.` with the position id
   
   ```java
    public Seq<String> whisk$core$entity$EntityPath$$apply(Seq<String> parts)
       throws IllegalArgumentException
     {
       Invoker..MODULE$.invoked(3331, 
"/absolute/path/of/openwhisk/openwhisk/common/scala/build/scoverage"); 
Invoker..MODULE$.invoked(3329, 
"/absolute/path/of/openwhisk/openwhisk/common/scala/build/scoverage"); 
Invoker..MODULE$.invoked(3327, 
"/absolute/path/of/apache/openwhisk/openwhisk/common/scala/build/scoverage"); 
Object 
   ```
   
   Now as test execute and the code path gets executed it would record the 
invocation in `build/scoverage/scoverage.measurements.xxx` files. Post test 
complete a task is run which consumes the measurement file and 
scoverage.coverage.xml to produce a `build/reports/scoverage/scoverage.xml` 
which the coverage file for that module. Then multiple coverage file can be 
combined to produce the final report
   
   ### Runtime classpath implication
   
   For the instrumented code to work we need to include following deps in 
classpath (current version 1.3.1)
   
   1.  org.scoverage:scalac-scoverage-plugin_2.11
   2. org.scoverage:scalac-scoverage-runtime_2.11
   
   This is simpler for unit test or tests where code from common, invoker and 
controller is run in same vm as test cases as the scoverage gradle plugin 
adapts the classpaths. However it posses some challenge with Docker setups
   
   [1]: https://plugins.gradle.org/plugin/org.scoverage
   [2]: https://github.com/scoverage/scalac-scoverage-plugin

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to