1 / 11

Code Coverage - Department of Computer Engineering

This presentation is on Code Coverage and is presented by Prof. Ramkrushna Maheshwar, of the department of Computer Engineering at Hope Foundationu2019s International Institute of Information Technology, Iu00b2IT. The topics discussed include coverage criteria, Commands, Procedure, Source File (add.py) and how code coverage works.

Download Presentation

Code Coverage - Department of Computer Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CODE COVERAGE Prof. Ramkrushna Maheshwar Assistant Professor Department of Computer Engineering Hope Foundation’s International Institute of Information Technology, I²IT www.isquareit.edu.in

  2. Code Coverage 1) In software engineering, test coverage is utilized to depict how much the source code of a program is executed when a specific test suite runs. 2) A program with high test inclusion, estimated as a rate, has had a greater amount of its source code executed amid testing which recommends it has a lower possibility of containing undetected programming bugs contrasted with a program with low test inclusion. 3) A wide range of measurements can be utilized to ascertain test inclusion; the absolute most fundamental are the level of program subroutines and the level of program articulations called amid execution of the test suite. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  3. coverage criteria Function coverage – Has each function (or subroutine) in the program been called? ● Statement coverage – Has each statement in the program been executed? ● Branch coverage – Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed? ● Condition coverage (or predicate coverage) – Has each Boolean sub- expression evaluated both to true and false? ● Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  4. Commands Run – Run a Python program and collect execution data. ● Report – Report coverage results. ● html – Produce annotated HTML listings with coverage ● results. xml – Produce an XML report with coverage results. ● annotate – Annotate source files with coverage results. ● erase – Erase previously collected coverage data. combine – ● Combine together a number of data files. debug – Get ● diagnostic information. ● Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  5. Procedure ●$ pip install coverage ●$ coverage --version Coverage.py, version 4.2 with C extension Documentation at https://coverage.readthedocs.io ●$ gedit add.py source file to which we apply code coverage. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  6. Source File ( add.py ) • // Source Program add.py • # iterate through rows for i in • X = [[12,7,3], range(len(X)): • [4 ,5,6], • # iterate through columns for j in • [7 ,8,9]] range(len(X[0])): • Y = [[5,8,1], • result[i][j] = X[i][j] + Y[i][j] a = 1 • [6,7,3], • if a==1: • [4,5,9]] • print "a=1" else: • result = [[0,0,0], • print "a!=1" for r in result: • [0,0,0], • print(r) • [0,0,0]] Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  7. Procedure • [student@localhost ~]$ coverage run add.py ● • a=1 • [17, 15, 4] • [10, 12, 9] • [11, 13, 18] ● student@localhost ~]$ coverage report Name Stmts Miss Cover ---------------------------- add.py 12 1 92% Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  8. Procedure ●$Coverage xml add.py The xml command writes coverage data to a “coverage.xml” file. ●$ coverage html -d coverage_html The -d argument specifies an output directory, defaulting to “htmlcov”. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  9. How it works Coverage.py works in three phases : 1)Execution : Coverage.py runs your code, and monitors it to see what lines were executed. 2)Analysis : Coverage.py examines your code to determine what lines could have run. 3)Reporting : Coverage.py combines the results of execution and analysis to produce a coverage number and an indication of missing execution. The execution phase is handled by the coverage run command. The analysis and reporting phases are handled by the reporting commands like coverage report or coverage html. Hope Foundation’s International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www.isquareit.edu.in ; Email - info@isquareit.edu.in

  10. Reference : • https://en.wikipedia.org/wiki/Code_coverage • https://ordepdev.me/posts/code-coverage • https://coverage.readthedocs.io/en/v4.5.x/

  11. THANK YOU For further information please contact Prof. Ramkrushna Maheshwar Department of Computer Engineering Hope Foundation’s International Institute of Information Technology, I²IT P-14, Rajiv Gandhi Infotech Park, MIDC Phase I, Hinjawadi, Pune – 411 057 Phone - +91 20 22933441 www.isquareit.edu.in | ramkrushnam@isquareit.edu.in | info@isquareit.edu.in

More Related