Presentation & Discussion on Testing and Debugging Share your experience Learn from each other.

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Advertisements

Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Monday, Mar 24, 2003Kate Gregory with material from Deitel and Deitel Week 11 Exceptions.
Programming Types of Testing.
Interactive Media and Game Development Debugging.
BIM313 – Advanced Programming Techniques Debugging 1.
Debugging Introduction to Computing Science and Programming I.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
How to Debug VB .NET Code.
Interactive Media and Game Development Debugging.
Programming Fundamentals (750113) Ch1. Problem Solving
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved For Loops October 16, 2013 Slides by Evan Gallagher.
HOMEWORK REVIEW This is an if else statement layout if (condition) { code to be executed if condition is true; } else { code to be executed if condition.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
BİL528 – Bilgisayar Programlama II Making Decisions, Loops, Debugging, Designing Objects Using Classes 1.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
CSE 332: C++ debugging in Eclipse C++ Debugging in Eclipse We’ve now covered several key program features –Variable declarations, expressions and statements.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Program Errors and Debugging Week 10, Thursday Lab.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
Data Structures and Debugging Dr. Nancy Warter-Perez June 18, 2003.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Review, Pseudocode, Flow Charting, and Storyboarding.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Error messages 25-Apr-17.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Introduction to Exceptions in Java CS201, SW Development Methods.
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
5.01 Understand Different Types of Programming Errors
Completing the Problem-Solving Process
Testing and Debugging.
Computer Programming I
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Cracking the Coding Interview
5.01 Understand Different Types of Programming Errors
Chapter 15 Debugging.
Common C Programming Errors, GDB Debugging
Programming Fundamentals (750113) Ch1. Problem Solving
When your program crashes
Chapter 15 Debugging.
Our Environment We will exercise on Microsoft Visual C++ v.6
Basic Debugging (compilation)
CSCI 380: Operating Systems Instructor: William Killian
An Introduction to Debugging
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Chapter 15 Debugging.
CHAPTER 6 Testing and Debugging.
Chapter 15 Debugging.
Presentation transcript:

Presentation & Discussion on Testing and Debugging Share your experience Learn from each other

Common Testing and Debugging Problems in Candiceland The Gold Star Award - Only applies when you discover that the reason nothing you try works is because you did something so silly that you’ve been overlooking it for hours - Common examples include simple logic errors, forgotten semicolons or curly braces - This simple problem produces an incomprehensible error message - For each hour that this simple error stumps you, you get a gold star! The Unhandled Exception - Can sometimes be solved by using the debugger to step through the code line by line and carefully keeping track of where everything is - This requires a phenomenal amount of patience, time, and dedication

How to Program with Fewer Errors - Do not try to program when you are tired, have had too much sugar, or are trying to knit -The more incomprehensible the error message, the simpler the solution to the problem and the harder it is to find - Keep careful track of variables and dynamic memory

Common Mistakes in Code: Having brackets in the wrong place By misplacing a bracket a whole function might not work or work incorrectly Not checking things (ex: assert checks, if statements, etc.) If values are not checked before the function continues functions won’t properly run and the rest of your program will run into errors when a wrong value is passed Katie Ouellette

How to find errors in your code: Make test code to run through the program Brake the program down into steps ex: When test code is given for you and you don’t know where your code has an error, add a cin statement so that the code will stop and prompt you. This way you know exactly where the code had a problem and you can work from there Print the code out and work through each function by hand. Tracing the values and make sure everything is in the right order. Draw pictures of what is happening with your data and your assignments Test each function with all different kinds of test data to stretch the code. Maybe the error is occurring at the edges of the code’s capability

Katie Ouellette To Write Code Without Errors: Plan the code out as much as you can before hand Write pseudo code Walk through the pseudo code to see how it will work Don’t go to fast! - This will just lead you to not see any errors you make in your code Step away from your code for awhile if you are having a problem. Then when you come back you can see it with fresh eyes.

TESTING AND DEBUGGING By Tasnia Tahsin Common mistakes in my code:  Wrong pseudocode- often miss certain conditions that have to be considered  Syntax errors- mainly placing semi colons or brackets at wrong places How I discover and fix errors in my code  Testing: Test each function in my code with the test program using inputs that are most likely to cause errors like boundary inputs.Test each function in my code with the test program using inputs that are most likely to cause errors like boundary inputs. Choose different inputs to execute each line of codeChoose different inputs to execute each line of code Check code using ‘exam’ fileCheck code using ‘exam’ file  Debugging- use debugging tool to fix errors

TESTING AND DEBUGGING By Tasnia Tahsin The debugging tool I use and how  Use Visual Studio debugging tool First place breakpoints before functions which contain bugsFirst place breakpoints before functions which contain bugs Step through each line of code and step into functions present there until the exact point where the bug is present is foundStep through each line of code and step into functions present there until the exact point where the bug is present is found Fix the bugFix the bug How to write a program with less bugs in the first place  Take into account the different conditions that have to be handled within the function  Reason carefully and write a good pseodocode  Remember the invariant of the class while writing the code

Nina’s Slides Common Mistakes of My Programs -Not thinking about error checking when I first type out the code. -Usually leads to segmentation faults. ☺ -Simply forgetting to watch out for syntax errors when I first write the code. -The compiler usually catches these. Discover and Fix -When the compiler catches the syntax problems, I can usually just go to the line with the syntax error and correct it. -This usually takes a few minutes. -But when I get a segmentation fault from a run-time error, it usually takes me a while to step through the code to find where my code hit and error. -This can take a good ten minutes if I’m lucky. But during the time I do my homework, writing the code takes 30 minutes, debugging takes an hour or more.

Debugging Tool Used -When debugging, I usually run the program in debug mode, so when it hits an error, I can break from the running program to look at the code and where the error is happening. -If it is not as easy as looking at the code where the error happened, I look at values of variables to see what made the program angry. Then I try to find the last function of mine that manipulated the data in that variable. -If all else fails, I step through the program, watching the values of the variables for each step, until I see where the erroneous value comes in. How to write a program with less bugs -To write a program with less bugs, I try to look more that how bad data will affect my functions. Using this knowledge I try to program more error checking into my functions, so that segmentation faults can happen less. -Also, I try to comment every line I write to make sense to me. If the way I wrote the program can’t be articulated into something that makes sense, I delete it and write a new line to take it’s place that does make sense.

My Common Errors a tragedy in two acts by Becca Groveman Think before you code! Gold Star Problems A common mistake: –can you find the gold star? class Example { … }

My Common Errors ACT TWO The Debugger and Why I Am Reluctant To Use It

Testing and Debugging Silvia-Dana Marin

The common mistakes in my programs Boundary limits in loops (for loops, while-loops) Dangling pointers (within linked lists) Forgetting to add preconditions to the methods

How discovered and fixed them While testing the methods with the test program By verifying the post and pre conditions for the methods in the documentation file Through the exam files →Most errors could be fixed by re-writing the pseudo-code for the methods (especially in the case of loop-boundaries) and by drawing the way the memory of the computer works →Some of the errors were discovered and fixed by using the debugger

The debugging tool you use and how I use the Debugger Toolbar provided with Visual Studio 6.0 for C++

How to write a program with less bugs in the first place By verifying that all the preconditions and post conditions are fulfilled by the method By testing the pseudo-code before beginning coding (especially in the case of boundary limits or pointers and deletions of pointers) By testing each function at a time And by beginning with a smaller number of functions for each class

Debugging Technique Self-testing Test boundary values Test random values When testing Identify where is wrong Correct only that part and try again

Example1 void sequence::operator =(const sequence& source) { //if (data == source.data) return; list_clear(data); list_copy(source.data, data, tail); if (source.prev != NULL) prev = list_search(data, source.prev->data()); else prev = NULL; if (source.curr != NULL) curr = list_search(data, source.curr->data()); else curr = NULL; tail = data; if (tail != NULL) while (tail->link() != NULL) tail = tail->link(); total = source.total; } SELF-ASSIGNMENT TEST FAILED – it ’ s easy to see that the commented statement is missing

Example2 void sequence::operator =(const sequence& source) { if (data == source.data) return; //list_clear(data); //list_copy(source.data, data, tail); if (source.prev != NULL) prev = list_search(data, source.prev- >data()); else prev = NULL; if (source.curr != NULL) curr = list_search(data, source.curr- >data()); else curr = NULL; tail = data; if (tail != NULL) while (tail->link() != NULL) tail = tail->link(); total = source.total; }

Example2 TEST1 (attach/insert) Failed! (in addition to assignment operator, heap leak testing, and you get a crash) … (the first, second case okay) I am now using attach to put 10,20,30 in an empty sequence. Then I move the cursor to the start and insert 5. Testing that size() returns 4... Passed. Testing that is_item() returns true... Passed. The cursor should be at item [0] of the sequence (counting the first item as [0]). I will advance the cursor to the end of the sequence, checking that each item is correct... Cursor fell off the list too soon. Failed. Test of the list's items failed.

Example2 int test1( ) { sequence empty; // An empty list sequence test; // A list to add items to … // Test the insert function to add an item at the front of a list cout << "I am now using attach to put 10,20,30 in an empty sequence.\n"; cout << "Then I move the cursor to the start and insert 5." << endl; test = empty; test.attach(10); test.attach(20); test.attach(30); test.start( ); test.insert(5); if (!correct(test, 4, 0, items1)) return 0; }

common mistakes  for loops (flipping greater than and less than signs) ‏  not moving current to the right spot so entry gets attached/inserting to the wrong spot (one off) ‏  increasing used twice CLS

finding errors  Run exam files to find if you have incorrect output.  If so, run test file and/or debug  My debugging technique:  If applicable, comment out all functions except the one you're testing and essential functions (constructors, destructors, etc.) ‏  Test input for a certain function  If the output is incorrect, use cout statements to pinpoint location of error  Use either given test files or write your own to test specific functions CLS

debugging tool  Eclipse has a debugger:  allows you to set breakpoints  allows you to trace variables  I don't use this often  cout statements work better for me CLS

for fewer errors before you start:  write pseudocode  make a list of common possible errors that may occur with a given function and take those into consideration when writing the code for your function  write functions one at a time and try them out one at a time CLS