DOC PREVIEW
UW CSE 303 - Lecture Notes

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 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 12 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 12 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 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

'&$%CSE 303:Concepts and Tools for Software DevelopmentHal PerkinsAutumn 2007Lecture 16— gdb continued; TestingCSE303 Autumn 2007, Lecture 16 1'&$%Where are We• In the middle of learning to debug with gdb– To learn general features of breakpoint-debugging– To learn specifics of gdb– To learn general debugging “survival skills” (don’t panic)• Some very basic “software-engineering” topics in the midst oftools (take 403)– Today: testing (how, why, some terms)– Later: (partial) specificationCSE303 Autumn 2007, Lecture 16 2'&$%gdb review• For examining program state while a program is stopped or after itcrashes– Move around the call stack, print variables, follow pointers,compare addresses, ...– Stepping, nexting, finishing, continuing, breaking∗ Know what these do, how they work, why they’re helpful∗ See the manual to remember and learn fancier features– Debuggers exist for many languages/compilers (e.g., jdb onattu for Java).– Must remember some gdb specifics (e.g., compile with -g).CSE303 Autumn 2007, Lecture 16 3'&$%A few tricksEveryone develops their own “debugging tricks”; here are a few:• Printing pointer values to see how big objects were.• Always checking why a seg-fault happened (infinite stack andarray-overflow very different)• “Staring at code” even if it does not crash• Printing array contents (especially last elements)• . . .Like any tool, takes extra time at first but designed to save you time inthe long run• Education is an investment.CSE303 Autumn 2007, Lecture 16 4'&$%Testing 1, 2, 3• Role of testing and its plusses/minuses• Unit testing or “testing in the small”• Stubs, or “cutting off the rest of the world” (which might notexist yet)CSE303 Autumn 2007, Lecture 16 5'&$%A little theory• Motto (Hunt and Thomas): “Test your software or your users will”• Testing is very limited and difficult:– Small number of inputs– Small number of calling contexts, environments, compilers, ...– Small amount of observable output– Requires more things to get right, e.g., test code• Standard coverage metrics (statement, branch, path) are usefulbut only emphasize how limited it is.CSE303 Autumn 2007, Lecture 16 6'&$%3 coverage metricsint f(int a, int b) {int ans = 0;if(a)ans += a;if(b)ans += b;return ans;}Statement coverage: f(1,1) sufficientBranch coverage: f(1,1) and f(0,0) sufficientPath coverage: f(0,0), f(1,0), f(0,1), f(1,1) sufficientBut even the example path-coverage test suite suggests f is a correct“or” function for C; it is not.CSE303 Autumn 2007, Lecture 16 7'&$%Colored boxes“black-box” vs. “white-box”• black-box: test a unit without looking at its implementation– Pros: don’t make same mistakes, think in terms of interface,independent validation– Basic example: remember to try negative numbers• white-box: test a unit with looking at its implementation– Pros: can be more efficient, can find the implementation’scorner cases– Basic example: try loop boundaries, “special constants”CSE303 Autumn 2007, Lecture 16 8'&$%Stubs• Unit testing (a small group of functions) vs. integration testing(combining units) vs. system testing (the “whole thing” whateverthat means)• How to test units (“code under test”) when the other code:– may not exist– may be buggy– may be large and slow• Answer: You provide a “fake implementation” of the other codethat “works well enough for the tests”.– Fake implementation is as small as possible, so the functionsare often called “stubs”.• Tools like JUnit et seq. exist to support unit testing — takeadvantage of them when they make senseCSE303 Autumn 2007, Lecture 16 9'&$%Stubbing techniquesIt’s an art, not a science. Kinds of techniques that are useful:• Instead of computing a function, use a small table of pre-encodedanswers• Return wrong answers that won’t mess up what you’re testing• Don’t do things (e.g., print) that won’t be missed• Use a slower algorithm• Use an implementation of fixed size (an array instead of a list?)• ... other ideas?Lecture-size example can be tough, but we can try to get the ideaacross.CSE303 Autumn 2007, Lecture 16 10'&$%Eating your vegetables• Make tests:– early– easy to run (e.g., a make target with an automatic diff againstsample output)– that test interesting and well-understood properties– that are as well-written and documented as other code• Write the tests first (seems odd until you do it)• Write much more code than the “assignment requires you turn-in”• Manually or automatically compute test-inputs and right-answers?• Write regression tests and run on each version to ensure bugs donot creep in for stuff that “used to work”.CSE303 Autumn 2007, Lecture 16 11'&$%Testing – of whatSummary: Testing has some concepts worth knowing and using• Coverage• White-box vs. black-box• StubbingBut we made a big assumption, that we know what the code issupposed to do!Specification is a topic we will talk about shortly.CSE303 Autumn 2007, Lecture 16


View Full Document

UW CSE 303 - Lecture Notes

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Lecture Notes
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 Lecture Notes 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 Lecture Notes 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?