This preview shows page 1-2-3-4-5-6 out of 17 pages.

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

Unformatted text preview:

CMSC 433 – Programming LanguageTechnologies and ParadigmsSpring 2005TestingSome slides adapted from FSE’98 Tutorial by Michal Young andMauro Pezze’2Testing• Execute program on sample input data– Check if output correct (acceptable)• Goals– Increase confidence program works correctly• Acceptance Testing– Find bugs in program• Debug Testing3Simple Example% java TestServlet HelloWorld /FooBar/Test > out HTTP/1.0 200 Content-Type: text/plain Hello /FooBar/Test% diff out expectedOutput4Limitations of Testing• Program runs on (very small) subset of input data– Exhaustive testing usually impossible• Too large input space (possibly infinite)• Many situations hard to test– Parallel code (due to non-determinism)– Hard-to-reach states (e.g., error states)– Inadequate test environment (e.g., lack of hardware)• Testing cannot prove absence of bugs– Especially a problem in security5Black Box Testing• Pick subcomponent of program– Internals of component not considered• Give it inputs• Compare against expected outputsinputs outputssubcomponentbeing testedIs it correct?oracle6Black Box Testing• Pick subcomponent of program– Internals of component not considered• Give it inputs• Compare against expected outputs– But how do I know what the expected outputs are?– Depends on the specification (more later…)7The Test Case Generation Problem• How to choose tests that will show that myprogram works?– Must consider “operational scenarios”• What is legitimate input?• What is the correct action or output?– Must consider “abnormal behaviors” as well• How can I make sure that all of the importantbehaviors of my program have been tested?– Usually, you can’t!8Test Cases via Specifications // Return true if x in a, else returns false boolean contains(int[] a, int x);• Two “paths” in specification– Test case where x is in a– Test case where x is not in a9Test Cases via Inferred Implementation• Think about how the implementation might look– Test by boundary condition• What test cases are likely to exercise the samelogic?• Want to avoid redundant tests, to save time– Test by common mistake• What cases my be tricky to implement?• At the same time, tests should still beimplementation-independent10Test Cases via Boundary Conditionsinterface List { ... Inserts the specified element at the specified position in this list(optional operation). Shifts the element currently at that position (ifany) and any subsequent elements to the right (adds one to theirindices). public void add(int index, Object element)}•Test with empty list•Test with index at first/last element•Others?11Test Cases via Common Mistakes // Appends l2 to the end of l1 void append(List l1, List l2);• Does append work if l1==l2? class A { ...boolean equals(...); }• Does equals work if operand is an Object?12White/Glass Box Testing• Pick subcomponent of program• Give it inputs– Based on component code• If you don’t execute the code, you don’t knowwhether or not it works• Compare against correct outputs (properties)inputs outputssubcomponentbeing testedIs it correct?oracle13Statement CoverageOne test case (n=1, a[0]=-7, x=9) covers all statementsFaults handling positive values of a[i] not revealedint select(int[] a, int n, int x) {int i=0;while (i<n && a[i] <x) {if (a[i]<0) a[i] = - a[i];i++;}return 1;}i++i<n and a[i] <xa[i]<0a[i] = - a[i];return 1truefalsetruefalsei=014Branch Coveragei=0i<n and a[i] <xa[i]<0a[i] = - a[i];return 1truefalsetruefalseMust add test case (n=1, a[0]=7, x=9) to cover false branch of ifFaults handling positive values of a[i] revealed.Faults exiting the loop with a[i] <x not revealedint select(int[] a, int n, int x) {int i=0;while (i<n && a[i] <x) {if (a[i]<0) a[i] = - a[i];i++;}return 1;}i++15Condition Coveragei=0i<n and a[i] <xa[i]<0a[i] = - a[i];return 1truefalsetruefalseBoth i<n and a[i]<x must be false and true for different tests.Must add tests that cause loop to exit for a value greater than X.Faults that arise after several loop iterations not revealed.int select(int[] a, int n, int x) {int i=0;while (i<n && a[i] <x) {if (a[i]<0) a[i] = - a[i];i++;}return 1;}i++16Structural Coverage Testing• Adequacy criteria– If significant parts of program structure are not tested,testing is surely inadequate• Control flow coverage criteria– Statement (node, basic block) coverage– Branch (edge) coverage– Condition coverage• Attempted compromise between the impossibleand the inadequate17Granularity of Tests• Unit testing– Individual components of a program are tested• Methods• Classes/packages• Processes of a distributed system• Integration testing– Test case inputs to subsystem, multiple subsystems, orthe whole program, and outputs examined18White/Glass Box vs. Black Box• Black box– depends on spec– scales up• different techniques atdifferent granularitylevels– cannot reveal code coverageproblems• same specificationimplemented withdifferent modules• White box– depends on control or dataflow coverage– does not scale up• mostly applicable at unitand integration testinglevel– cannot reveal missing patherrors• part of the specificationthat is not implemented19Testing Activities• Test case execution is only a part of the process• Must also consider– Test case generation– Test result evaluation• Planning is essential– To achieve early and continuous visibility– To choose appropriate techniques at each stage– To build a testable product– To coordinate complementary analysis and testing20The Testing Environment• Want to create a scaffold for executing tests– Code infrastructure to run tests and check output• Many benefits– Can automate testing process– Useful for regression testing• But, can take some time to implement21Testing Environment Components• A user to generate input for tested component• An oracle for verifying the results are correct• These two may be combined into a single system22Unit Testing with Junit• Testing environment for writing black-box tests– Write special TestCase classes to test other classes– Several ways to use/set up test cases• Can be downloaded from – http://www.junit.org23Junit Philosophy• Iterative, incremental process– Write small black-box test cases (as needed)– Test-as-you-go• I.e., after changes, when new method added, whenbug identified• Junit test cases


View Full Document

UMD CMSC 433 - Testing

Documents in this Course
Trace 1

Trace 1

62 pages

Reflection

Reflection

137 pages

Testing

Testing

25 pages

Paradigms

Paradigms

10 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Java RMI

Java RMI

17 pages

Trace 1

Trace 1

46 pages

Jini

Jini

4 pages

Final

Final

15 pages

Java RMI

Java RMI

13 pages

Testing

Testing

16 pages

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