DOC PREVIEW
Duke CPS 100E - Testing and Debugging

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 100E18.1Testing and DebuggingRobert A WagnerCompSci 100E18.2Overviewÿ Testing Running program against test input cases, chosen to reveal correct and incorrect behaviorsÿ Debugging Identifying, localizing, and fixing problemsCompSci 100E18.3Test Case Designÿ Exhaustive: Try every possible input Usually NOT feasibleÿ Black box: Guess at “problem” inputs Based only on problem description Often misses problemsÿ White box: Use knowledge of program structure to design cases that exercise itCompSci 100E18.4Example: GroupCheckÿ Program supposed to check for balanced parentheses, using <>[]{}() as the groupingsÿ Report “location of an error” <pre>[html{]a href="works.html"}</pre> is not valid at position 11 because the ] is trying to close the { 000000000011111111112012345678901234567890<pre>[html{]a href="works.html"}</pre> Shows that 0-origin indexing is used for location, and that “first point at which error detected” is meantCompSci 100E18.5ÿ Exhaustive How many different strings are needed?ÿ Guess at possible errors Other?o Mismatches: “{]”, “[}”, “<}” … How many?o What about “too many or too few parens”?“{“, “}”, “(“, “)” Any more? Try complex correct strings, tooo Each non-paren character as a single character Stringo Strings which nest parens deeply, with + w/o errorsGroupCheck (continued)CompSci 100E18.6Debuggingÿ Identify error (GroupCheck example) Is error location correct? Carefully count!!o “Correct” is special case of location: –1.ÿ Locate statements that produce this error Hypothesize, then verify hypothesis by getting more output from the program near error locationo Use interactive debugger?I haven’t found good way to get it to show variable valueso Add System.out.println() statementsÿ Modify program to fix error Try hard not to introduce new errors!CompSci 100E18.7Interactive Debuggerÿ Allows you to stop program at “step” you choose “on the fly” At a statement or method entranceo Only if some test on variables is trueo After K executions of this statement Whenever something changes some variable’s value (watchpoint)ÿ While stopped, lets you examine contents of any variables. Variable values should be displayed in human-readable formÿ Allows resuming execution, to reach next suspected “error site”CompSci 100E18.8Eclipse Debuggerÿ Displays variable values as numeric pointer to an Object. Not helpful There’s some way to “evaluate expressions”, but those expressions have already be in the code.o Not flexibleo I haven’t figured out how to do thisÿ Using println(), I’ve had to call Arrays.deepToString() to print contents of an arrayCompSci 100E18.9Fixing Errorsÿ Understand the program READ what it SAYS, not what you THOUGHT you wrote Explain what it does to someone else who questions whether:o It does what you say it doeso What you say it does will solve the problemo Other cases you haven’t considered exist Use debugging statements to verify understanding, show what’s going on inside complex parts Place debugging statements to show if you’ve found the source of erroneous output, follow flow of bad data backwards. Add extra test cases to test hard-to-understand partsCompSci 100E18.10Fixing Errors (2)ÿ Acid test of understanding: Try fixing what you think is wrong, verify: That it fixed the problem you were working on Rerun ALL test cases, verify they’re still OKÿ I recommend fixing errors in the order you find themCompSci 100E18.11Binary Search for some errorsÿ Use when you need to find which statement is changing some variable, and your debugger does not allow “watchpoints”ÿ Run program “half way”, see if the variable has changed If not, run half the remaining steps If so, start program over, stop ¼ way Repeat till problem


View Full Document

Duke CPS 100E - Testing and Debugging

Documents in this Course
Topics

Topics

9 pages

Lecture

Lecture

3 pages

Notes

Notes

2 pages

Hashing

Hashing

19 pages

Lecture

Lecture

59 pages

Lecture

Lecture

6 pages

Lecture

Lecture

4 pages

Lecture

Lecture

20 pages

Lecture

Lecture

12 pages

Lecture

Lecture

12 pages

Lecture

Lecture

7 pages

Lecture

Lecture

8 pages

Lecture

Lecture

10 pages

Lecture

Lecture

4 pages

Notes

Notes

16 pages

Lecture

Lecture

5 pages

Lecture

Lecture

9 pages

Lecture

Lecture

4 pages

Lecture

Lecture

13 pages

Lecture

Lecture

6 pages

Lecture

Lecture

16 pages

Lecture

Lecture

5 pages

Lecture

Lecture

5 pages

Lecture

Lecture

12 pages

Lecture

Lecture

12 pages

Lecture

Lecture

10 pages

Sets

Sets

14 pages

Lecture

Lecture

9 pages

Lecture

Lecture

4 pages

Test 1

Test 1

7 pages

Load more
Download Testing and Debugging
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Testing and Debugging and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Testing and Debugging 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?