Obtaining Code Coverage Information While running Functional Test Cases
http://www.freepik.com

Obtaining Code Coverage Information While running Functional Test Cases

Frontend Code Coverage

Problem Statement / Requirement:

  • We Required to obtain code coverage of Angular JS/React Application with the use of Istanbul, a JavaScript test coverage tool. 
  • The code coverage should be calculated when we execute and automate the application using selenium test cases or manual testing.

Proposed solution:

  • We can use "nyc" command line utility of istanbul for instrumenting the code so that we can capture the coverage.
  • The window.__coverage__  will be object where the coverage data will get stored.
  • We can the store the coverage obtained into the json file and run through report command to obtain the proper report of the application.

How the solution works:

Article content

Utilities addition

  • We need to add the command line utility of istanbul nyc using the command.
  • npm install --save-dev nyc
  • We can add it globally (system wide) or limited to application.

Changes in the package.json

  • We need to configure the package.json as per the requirements.
  • Addition of nyc configurations  e.g extension, parser plugins, reporter, exclude & include etc.

Advantages

  • nyc supports majority of the framework.
  • It gives the detailed code coverage e.g how many branches, statements, and lines got covered.
  • It provides you with collection of reports e.g, both text on terminal and html report
  • We can obtain the code coverage using istanbul without having to do unit testing i.e it works well with manual testing as well automated test cases.
  • It supports mocha, ava etc,which are polular unit testing frameworks. 

Disadvantages

Additional tool tried for React JS

  • We have tried cypress CRA for the react JS application and it only works with React JS.

References

Article content
Article content
Article content

Java Code Coverage

Problem Statement

  • We Required to obtain code coverage of Java Application with the use of Jacoco code coverage tool
  • The code coverage should be calculated when we execute and automate the application using selenium test cases or manual testing.

Proposed solution

  • We propose to use the jacoco agent which sits between the application and the request which are coming up to the application with JVM
  • We just need to deploy the application with agent

How the solution works

Article content

Sample Commands

Java -javaagent:PATH_TO_JACOCO_AGENT_JAR/jacocoagent.jar=destfile=PATH_TO_GENERATE_JACOCO_EXEC_FILE/jacoco.exec,output=file,append=false

java -jar PATH_TO_JACOCO_DIRECTORY/jacococli.jar report jacoco.exec --classfiles PATH_TO_APPLICATION_CLASS_FILES --html PATH_TO_HTML_REPORT_DIRECTORY

References

 




To view or add a comment, sign in

Others also viewed

Explore topics