Software Testing
Table of Contents
- 1. A Famous Quote
- 2. Overview/Goals
- 3. Definition of a "Test"
- 4. Test Generation
- 5. Test Coverage
- 6. Testing Techniques
- 7. Equivalence Class Testing
- 8. Unit testing, Integration Testing
- 9. Testing of Interactive Programs
- 10. Test Driven Development (TDD)
- 11. Project Specific Lecture
- 12. References
- 13. End
1 A Famous Quote
"Testing shows the presence, not the absence, of bugs" – Edsger W. Dijkstra, 1969, Turning Award Winner 1972
2 Overview/Goals
2.1 Overview
- You may have understood testing on a very intuitive basis
- Make this understanding more rigorous
- Software testing v testing in engineering
2.2 Assumptions
- Assumption: Did not practice Correct by Design.
- Assumption: Life cycle: We are "done" with development. We shall test and debug. Fix errors, and loop over this step.
- Assumption: We know what the results of a test ought to be. But, how do we know? Not as simple as knowing sqrt(x)!
2.3 Goals of Software Test Design
- "Hope" to fail.
- Not randomly generated tests
- Known examples of hangs and crashes
- 100% coverage of source code
- Edge cases
- Pass "old" tests (Regression Tests)
- Minimize test costs (How "much" testing?)
2.4 Goal of Debugging
- Identify the location where errant behavior begins
- Definition of a "Errant Behavior"
- Can we recognize errant behavior? How soon?
- Repeatability of Tests (i.e., test results)
- In the presence of non-determinacy (due to concurrency and distributed-ness)
2.5 Test Suites
- "Smoke" Test description on Wikipedia
- Conformance/ Acceptance Tests [part of Requirements and Specs]
- Regression description on Wikipedia
- Unit tests
- Integration tests
- Fuzzing https://en.wikipedia.org/wiki/Fuzzing
3 Definition of a "Test"
- test io pair: input and its expected output
- "test vector" refers to the inputs given at one time
- input includes: actual arguments, state of files, databases, …
- everything the program "reads"
- output: as above
- everything the program "writes"
- test fails if observed output != expected
- hangs v crashes; both => fail
4 Test Generation
- Generate the io pairs, with high likelihood of test failures
- Assume for now that input is text, and the output is text
- when it is a test of an "internal" component, the io may not be a
"text/text" pair
- Unit testing solves this problem
4.1 Research on: Formal Specs => Tests
- Offutt, Jeff, and Aynur Abdurazik. "Generating tests from UML specifications." In UML99 – The Unified Modeling Language, pp. 416-429. Springer Berlin Heidelberg, 1999. Reference
- Pradel, Michael, and Thomas R. Gross. "Leveraging test generation and specification mining for automated bug detection without false positives." In 34th International Conference on Software Engineering (ICSE), pp. 288-298. IEEE, 2012. Reference
5 Test Coverage
- Can we construct tests that exercise every line of code?
- Statement coverage: execute each statement (at least) once
- Branch coverage: Execute each branch after a condition statement
- Path coverage: Execute all paths through the code
- Tools to track coverage
- C/C++: gprof, gcov/lcov, googletest, …
- Java: eCobertura, CodeCover, EclEmma, IdeaJ
- Does 100% coverage and no failures, guarantee that software is fault-free?
6 Testing Techniques
- Black box testing (aka functional testing): Uses no info re internals
- White box testing (aka structural testing): Uses all info re internals
- Worst/Special Case Testing
- Errors seem to cluster at boundaries
- What if values fall outside their ranges
- "Torture" (Stress) Tests
- Donald E. Knuth, "A torture test for TEX", http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tripman.pdf, 163pp, Version 3, January 1990.
7 Equivalence Class Testing
- Goal: Reduction of human/computer testing effort
- Divide the test vectors into subsets so that test coverage is the same
- The program is likely constructed so that it either succeeds or fails for each of the values in that class
- To test for robustness: for each equivalence class of valid inputs, devise equivalence classes of invalid inputs
- "cover" a class: Construct tests choosing one value from the class
- The goal is to cover all equivalence classes
8 Unit testing, Integration Testing
- OOP and programming language (PL) neutral term "unit" cf. class, method
- Unit test: test one method of one isolated class with one thread
- Tools for unit testing: JUnit and TestNG (both for any JVM based PL)
- Integration test: Test (all) the units together. It occurs after unit testing and before validation testing.
- see separate lectures
9 Testing of Interactive Programs
- Input generated in "real" time
- Output observed in "real" time
- Correctness judgement?
- Book: Don Libes, "Exploring Expect: A Tcl-based Toolkit for Automating Interactive Programs", O'Reilly Media, Inc., 2010, 606 pages. Look it up in WSU Library Safari Books.
- The "expect" is a standard package in Debian/Ubuntu systems
10 Test Driven Development (TDD)
- Testing impacts other phases of life cycle.
- We assumed above that implementation is "done". But, testing should be done during development.
- TDD is done as follows. Repeat until code is "complete":
- Add a test.
- Run all tests and see the new one fail.
- Make a (little) change.
- Run all tests and see them succeed.
- Refactor to remove duplication.
- ../Maintenance/KentBeck_TDD_byexample.pdf book extract 137pp. Ken
Beck made popular the TDD, as a phrase.
- Full book: Kent Beck, Addison-Wesley, Boston, MA, 2003. 216 pp. ISBN 0321146530. Reference.
- Book review by Charles Ashbacher in Journal of Object Technology, vol. 2, no. 2, March-April 2003, pp. 203-204.
11 Project Specific Lecture
12 References
- Glenford J. Myers, Corey Sandler, and Tom Badgett, The Art of Software Testing, 3rd Edition, John Wiley & Sons, Inc. 2011. Reference.
- http://en.wikipedia.org/wiki/Mutation_testing Required Reading.
- Pfleeger and Atlee, Software Engineering, 4e, slides are at
http://wps.prenhall.com/esm_pfleeger_softengtp_4/. Following slides
are Required Reading.
- ./Pfleeger-Atlee-08.ppt Chapter 8 - Testing the Programs
- ./Pfleeger-Atlee-09.ppt Chapter 9 - Testing the System
- ./Pfleeger-Atlee-10.ppt Chapter 10 - Delivering the System
- Barr, Earl T., et al. "The [Test] Oracle Problem in Software Testing: A Survey." IEEE transactions on software engineering 41.5 (2015): 507-525pp. "Given an input for a system, the challenge of distinguishing the corresponding desired, correct behaviur from potentially incorrect behavior is called the "test oracle problem". http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6963470. Required Reading.
- http://courses.cs.washington.edu/courses/cse331/16wi/L08/L08-Testing.pdf 40+ slides. Recommended Reading.
- Test-Driven Development – Extensive Tutorial. Open Source ebook https://leanpub.com/tdd-ebook Recommended Reading.
- ./TDD/tdd-calpoly-slides.pdf slides Recommended Reading.
- ./TDD/tdd-bneilsen-2006.pdf 30+ slides, cs.aau.dk; by Brian Nielsen + Arne Skou Recommended Reading.