A beginners guide to testing


Published on

Published in: Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

A beginners guide to testing

  1. 1. A beginners guide to testing Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822
  2. 2. Objectives <ul><li>Understand the basic concepts, terminology, and approaches to software testing. </li></ul><ul><li>Be able to apply this information to improve the quality of your own testing efforts during software development. </li></ul>
  3. 3. Why is testing important?
  4. 4. First National Bank (1996) <ul><li>Problem: </li></ul><ul><ul><li>An error at First National Bank of Chicago resulted in the balance of 800 customers being inflated by a total of $763 billion. </li></ul></ul><ul><li>Reason: </li></ul><ul><ul><li>Inadequate testing. Bank updated ATM transaction software with new message codes. Message codes were not tested on all ATM protocols, resulting in some ATMs interpreting them as huge increases to customer balances. </li></ul></ul>
  5. 5. Therac-25 (1985-1987) <ul><li>Problem: </li></ul><ul><ul><li>Six people were overexposed during radiation treatments for cancer by the Therac-25 radiation therapy machine. Three people were believed to have died from the overdoses. </li></ul></ul><ul><li>Reason: </li></ul><ul><ul><li>Inadequate testing. Hardware safety locks removed and replaced by software safety locks, which could be overcome by technician “type ahead”. </li></ul></ul>
  6. 6. Ariane 5 (1996) <ul><li>Problem: </li></ul><ul><ul><li>Ariane 5 rocket exploded on its maiden flight. </li></ul></ul><ul><li>Reason: </li></ul><ul><ul><li>Inadequate testing. Navigation package inherited from Ariane-4 without proper testing. New rocket flew faster, resulting in larger values of some variables, resulting in an attempt to convert a 64-bit floating number into a 16 bit integer. Code was caught and action taken was to shut down navigation system. </li></ul></ul>
  7. 7. ICS 314, Fall 2011 <ul><li>Problem: </li></ul><ul><ul><li>A student got a bad grade for ICS 314. </li></ul></ul><ul><li>Reason: </li></ul><ul><ul><li>Inadequate testing. The student did not learn how to write good test cases for their code. </li></ul></ul>
  8. 8. Testing fits into Validation and Verification <ul><li>Validation: </li></ul><ul><ul><li>Establishing the fitness of a software product for its use. </li></ul></ul><ul><ul><li>“ Are we building the right product?” </li></ul></ul><ul><ul><li>Requires interaction with customers. </li></ul></ul><ul><li>Verification: </li></ul><ul><ul><li>Establishing the correspondence between the software and its specification. </li></ul></ul><ul><ul><li>“ Are we building the product right?” </li></ul></ul><ul><ul><li>Requires interaction with software. </li></ul></ul>
  9. 9. Static vs. Dynamic V&V <ul><li>Static V&V: </li></ul><ul><ul><li>Software inspections </li></ul></ul><ul><ul><li>Static analysis of source code </li></ul></ul><ul><ul><ul><li>Control/data flow analysis </li></ul></ul></ul><ul><li>Dynamic V&V: </li></ul><ul><ul><li>Defect testing </li></ul></ul><ul><ul><ul><li>Looks for errors in functionality </li></ul></ul></ul><ul><ul><li>Load testing </li></ul></ul><ul><ul><ul><li>Looks for errors in scalability, performance, reliability </li></ul></ul></ul>
  10. 10. Issues <ul><li>Is it “testing” if you simply run the program to see what it does? </li></ul><ul><li>Is validation testing done best with static or dynamic testing? </li></ul><ul><li>Is verification testing done best with static or dynamic testing? </li></ul>
  11. 11. Why is testing hard? <ul><li>Exhaustive testing: </li></ul><ul><ul><li>Execute program on all possible inputs and compare actual to expected behavior. </li></ul></ul><ul><ul><li>Could “prove” program correctness. </li></ul></ul><ul><ul><li>Not practical for any non-trivial program. </li></ul></ul><ul><li>Practical testing: </li></ul><ul><ul><li>Select a tiny % of all possible tests. </li></ul></ul><ul><ul><li>Goal: executing the tiny % of tests will uncover a large % of defects present! </li></ul></ul><ul><ul><li>A “testing method” is essentially a way to decide which tiny % to pick. </li></ul></ul>
  12. 12. How do we determine which tests to write? Selected examples: <ul><li>Functional (black box) testing </li></ul><ul><ul><li>Use specification to determine the tests </li></ul></ul><ul><li>Structural (white box) testing </li></ul><ul><ul><li>Use coverage to assess the quality of tests </li></ul></ul><ul><li>Test-driven development </li></ul><ul><ul><li>Write tests as specification </li></ul></ul><ul><ul><li>Use tests to determine the implementation! </li></ul></ul><ul><li>Combinations of methods are acceptable! </li></ul>
  13. 13. Black box testing
  14. 14. Specification based testing <ul><li>Specification: </li></ul><ul><ul><li>A mapping between the possible “inputs” to the program and the corresponding expected “outputs” </li></ul></ul><ul><li>Specification-based testing: </li></ul><ul><ul><li>Design a set of test cases to see if inputs actually map to outputs. </li></ul></ul><ul><ul><li>Does not require access to source code </li></ul></ul><ul><li>Differences with White Box (coverage) testing: </li></ul><ul><ul><li>Can catch errors of omission. </li></ul></ul><ul><ul><li>Effectiveness depends upon the quality of specification </li></ul></ul>
  15. 15. Equivalence classes <ul><li>Goal: Divide the possible inputs into categories such that testing one point in each category is equivalent to testing all points in the category. </li></ul><ul><li>Provide one test case for each point. </li></ul><ul><li>Equivalence class definition is usually an iterative process and goes on throughout development. </li></ul><ul><li>Use heuristics to get you started designing your test cases. </li></ul>
  16. 16. Unit test design heuristics <ul><li>If input is a value: </li></ul><ul><ul><li>maximum value </li></ul></ul><ul><ul><li>minimum value </li></ul></ul><ul><ul><li>empty value </li></ul></ul><ul><ul><li>typical value </li></ul></ul><ul><ul><li>illegal value </li></ul></ul><ul><li>If input is a sequence: </li></ul><ul><ul><li>Single element </li></ul></ul><ul><ul><li>Empty sequence </li></ul></ul><ul><ul><li>Max and min element values </li></ul></ul><ul><ul><li>Sequences of different sizes </li></ul></ul><ul><ul><li>Illegal elements </li></ul></ul><ul><li>If I/O specification contains conditions: </li></ul><ul><ul><li>true </li></ul></ul><ul><ul><li>false </li></ul></ul><ul><li>If I/O specification contains iterations: </li></ul><ul><ul><li>zero times </li></ul></ul><ul><ul><li>1 time </li></ul></ul><ul><ul><li>> 1 time </li></ul></ul>
  17. 17. Web app design heuristics <ul><li>Every page is retrieved at least once </li></ul><ul><ul><li>Prevent 404 errors. </li></ul></ul><ul><li>Every link is followed at least once. </li></ul><ul><ul><li>Prevent 404 errors. </li></ul></ul><ul><li>All form input fields are tested with: </li></ul><ul><ul><li>Normal values </li></ul></ul><ul><ul><li>Erroneous values </li></ul></ul><ul><ul><li>Maximum/minimum values </li></ul></ul><ul><li>Always check response for appropriateness. </li></ul>
  18. 18. Tool support: JUnit
  19. 19. Tool Support: JUnitReport
  20. 20. White box testing
  21. 21. Statement coverage <ul><li>For a test case to uncover a defect, the statement containing the defect must be executed. </li></ul><ul><li>Therefore, a set of test cases which guarantees all statements are executed might uncover a large number of the defects present. </li></ul><ul><li>Whether or not the defects are actually uncovered depends upon the program state at the time each statement is executed. </li></ul>
  22. 22. Control flow coverages <ul><li>Control flow coverage adds conditions to statement coverage to raise the odds of discovering defects. </li></ul><ul><li>Branch coverage: </li></ul><ul><ul><li>Every conditional is evaluated as both true and false during testing. </li></ul></ul><ul><li>Loop coverage: </li></ul><ul><ul><li>Every loop must be executed both 0 times and more than 1 time. </li></ul></ul><ul><li>Path coverage: </li></ul><ul><ul><li>All permutations of paths through the program are taken </li></ul></ul>
  23. 23. JaCoCo: A Java Coverage Tool
  24. 24. JaCoCo: Drilldown to Package
  25. 25. JaCoCo: Drilldown to Class
  26. 26. JaCoCo: Red regions not tested
  27. 27. “ Coverage-driven test case design” <ul><li>1. Write some test cases to exercise your code in new ways. </li></ul><ul><li>2. Run your coverage tool. </li></ul><ul><li>3. If coverage is not 100%, go to 1. </li></ul>
  28. 28. “ Coverage-driven test case design” is bad! <ul><li>Using coverage data to drive the design of your tests often results in a poorly designed test case suite. (See readings.) </li></ul><ul><li>Instead, use coverage to assess the quality of your test method. </li></ul><ul><li>In a nutshell: </li></ul><ul><ul><li>Good test design method -> Good coverage </li></ul></ul><ul><ul><li>But not the other way around. </li></ul></ul>
  29. 29. Limitations of white-box testing <ul><li>Can catch bugs in code that has been written. </li></ul><ul><li>Cannot catch bugs in code that has not been written! </li></ul><ul><ul><li>Errors of omission: code that ought to have been written but wasn ’t </li></ul></ul><ul><ul><ul><li>Missing boolean conditions in IF statements </li></ul></ul></ul><ul><ul><ul><li>Missing exception handlers </li></ul></ul></ul><ul><li>To catch bugs in code that has not been written, you must compare behavior of program to its specification. </li></ul>
  30. 30. Quality assurance in this class <ul><li>You will use a combination of manual and automated quality assurance. </li></ul><ul><li>Automated QA: </li></ul><ul><ul><li>Use Checkstyle, PMD, FindBugs, and eliminate all warnings. </li></ul></ul><ul><li>Manual QA: </li></ul><ul><ul><li>Use JUnit to develop tests, use Jacoco to check coverage. </li></ul></ul><ul><ul><li>Use Code Review to look for remaining errors. </li></ul></ul>