presentation & discussion on testing and debugging share your experience learn from each other

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

Post on 21-Dec-2015

229 views

Category:

Documents


1 download

Embed Size (px)

TRANSCRIPT

  • Slide 1
  • Presentation & Discussion on Testing and Debugging Share your experience Learn from each other
  • Slide 2
  • 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 youve 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
  • Slide 3
  • 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
  • Slide 4
  • 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 wont properly run and the rest of your program will run into errors when a wrong value is passed Katie Ouellette
  • Slide 5
  • 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 dont 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 codes capability
  • Slide 6
  • 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 Dont 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.
  • Slide 7
  • 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
  • Slide 8
  • 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
  • Slide 9
  • Ninas 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 Im lucky. But during the time I do my homework, writing the code takes 30 minutes, debugging takes an hour or more.
  • Slide 10
  • 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 cant be articulated into something that makes sense, I delete it and write a new line to take its place that does make sense.
  • Slide 11
  • 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 { }
  • Slide 12
  • My Common Errors ACT TWO The Debugger and Why I Am Reluctant To Use It
  • Slide 13
  • Testing and Debugging Silvia-Dana Marin
  • Slide 14
  • 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
  • Slide 15
  • 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
  • Slide 16
  • The debugging tool you use and how I use the Debugger Toolbar provided with Visual Studio 6.0 for C++
  • Slide 17
  • 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
  • Slide 18
  • Debugging Technique Self-testing Test boundary values Test random values When testing Identify where is wrong Correct only that part and try again
  • Slide 19
  • 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
  • Slide 20
  • 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; }
  • Slide 21
  • 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.
  • Slide 22
  • 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