CSc 352: Testing and Code Coverage

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Odds And Ends – Switch Statement rIt is often necessary in programs to set up a set of cases, where.
Advertisements

Computer Science 2212a/b - UWO1 Structural Testing Motivation The gcov Tool An example using gcov How does gcov do it gcov subtleties Further structural.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
CSc 352 Freeing Dynamically Allocated Memory Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Coverage analysis using gcc (or g++) source code source code executable run results coverage gcc –ftest-coverage –fprofile-arcs myprogram.exe myprogram.cpp.
Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop –This means that java will test the condition before.
CSc 352 An Introduction to the C Preprocessor Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Recursion CS /02/05 L7: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Iteration.
Introduction to Computers and Programming Midterm Review Sana Odeh.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Computer Science 1620 Programming & Problem Solving.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
5.05 Apply Looping Structures
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
Coverage – “Systematic” Testing Chapter 20. Dividing the input space for failure search Testing requires selecting inputs to try on the program, but how.
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 10 - Testing.
CPS120 Introduction to Computer Science Iteration (Looping)
Greatest Common Divisor Jordi Cortadella Department of Computer Science.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CS101 Computer Programming I Chapter 4 Extra Examples.
SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr Jonas M. Larsen Memory debugging Recipe profiling.
1 Announcements  Homework 4 out today  Dec 7 th is the last day you can turn in Lab 4 and HW4, so plan ahead.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
CPS120 Introduction to Computer Science Iteration (Looping)
COP 3275 – Iteration and loops Instructor: Diego Rivera-Gutierrez.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
1 Steps to use Flex Ravi Chotrani New York University Reviewed By Prof. Mohamed Zahran.
The Problem If someone were to write a unit test with the goal of 90% coverage over the code, how is this 90% coverage verified? Not reaching test coverage.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
July 10, 2016ISA's, Compilers, and Assembly1 CS232 roadmap In the first 3 quarters of the class, we have covered 1.Understanding the relationship between.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
CSc 453 Lexical Analysis (Scanning)
CS 115 Lecture Flags.
CS1101X Programming Methodology
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Structure Charts Agenda: Use of Structure Charts Symbols How to create.
Structural testing, Path Testing
Fix BT Mail Error Code Call Toll-free
Machine-Independent Optimization
Code Coverage David Inglis November 18, 2018.
Topics Introduction to File Input and Output
GNU gcov (1/4) [from Wikipedia]
CSC 143 Error Handling Kinds of errors: invalid input vs programming bugs How to handle: Bugs: use assert to trap during testing Bad data: should never.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
CSc 352 An Introduction to the C Preprocessor
BugHint: A Visual Debugger Based on Graph Mining
Let’s all Repeat Together
GNU gcov gcov is a test coverage program running with gcc.
CSCI N207 Data Analysis Using Spreadsheet
GNU gcov (1/4) [from Wikipedia]
CSc 352: Elementary “make”
do/while Selection Structure
Introduction to Computer Science
CSc 352 An Introduction to make
CSCE 206 Lab Structured Programming in C
Topics Introduction to File Input and Output
CSc 352 File I/O Saumya Debray Dept. of Computer Science
CSc 352 Performance Tuning
CHAPTER 6 Testing and Debugging.
Structure Charts.
Presentation transcript:

CSc 352: Testing and Code Coverage Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu

make sure you use at least fifty different test inputs Testing and test cases make sure you use at least fifty different test inputs 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, … int main() { read x; if (x is odd) { compute payroll data; } else { delete all files; send rude email to boss; crash computer; It isn’t enough to have a lot of test cases. We have to make sure our tests “cover” the program adequately.

gcov: a code coverage analyzer test coverage program indicates how many times each line was executed marks code that did not get executed cumulative over a set of tests helps you understand how effectively your current test cases “cover” the code what additional test inputs you need in order to get better coverage needs the program to be compiled with additional gcc options

An example additional compiler flags input input input input input testing didn’t execute all of the code

An example input

An example input

Code coverage and testing Just because every line has been executed does not mean the program has been tested thoroughly we may want to test the same line of code under different conditions e.g.: a loop should be tested with values that cause 0, 1, and “many” iterations However, if some lines are not executed the program is definitely not thoroughly tested gcov helps us identify and fix this exception: “system errors” that may be difficult to create

gcov: summary code coverage testing tool works with gcc; needs additional compiler flags gcc –fprofile-arcs –ftest-coverage … shows execution frequency of each line of code reports % of lines covered by tests coverage values are cumulative delete *.gcda, *.gcno files to start afresh how many times each line was executed highlights lines not executed