Академический Документы
Профессиональный Документы
Культура Документы
Debugging
Testing finds problems
Unit test Integration test System test
Testing
Static testing
Inspection Code review Walk-through
Unit testing
Black box Functional testing White box Structural testing
Regression testing
CS1: chr, jeh, & tmh@cs.rit.edu
A Test Strategy
When code is messy, testing is hard. Java helps us by giving us the ability to test one piece (class) at a time.
Modularity
methods objects
Encapsulation
Data is packed with the methods (behaviors) that act on it. Private data means there is no other way to mess around with it.
CS1: chr, jeh, & tmh@cs.rit.edu
Test Strategies
Bottom-up test. Examine the Javadoc for the simplier methods, or for methods that are not dependent on others.
Debugging
Recreate the problem. Think about the cause - don't try ad hoc testing. Narrow it down. Use debug statements. Vary data to pattern failures. Create tests that rule out portions of code (narrow the search).
CS1: chr, jeh, & tmh@cs.rit.edu
Invoking the wrong constructor. Off-by-one errors in ifs and loops. Faulty Boolean expressions.
CS1: chr, jeh, & tmh@cs.rit.edu
Debugging
Fix one problem at a time. Retest. This is called regression testing. Be sure you didnt correct a problem in one place but create a new problem somewhere else. When all problems are fixed, rerun a full suite of tests.
Unit Testing
In object-oriented programming, the logical unit to test is the class.
Create an object. Call methods in different orders and with different argument values.
Methods that modify state are called mutators.
This sounds trivial, but it can actually be a lot of work. This is critical -- you must test or you wont know if your work is correct!
CS1: chr, jeh, & tmh@cs.rit.edu
Number of inputs - one valid, two invalid classes Set (enumeration) - one valid class (the set), one invalid class (the set complement)
Weekdays (not weekend days)
Must be constraint - one valid class (input satisfying constraint), one invalid class (input not satisfying constraint)
Start date must precede End date.
Sub-classes - an equivalence class should be divided into sub-classes if elements of a given EC are handled differently by the program
Passwords with fewer than 8 characters must include numbers as well as letters
2. 3.
Write test cases to cover each valid equivalence. Combine these into as few tests as possible. Write test cases to cover each invalid equivalence class. Specify a separate test for each of these.
Prof. John Noll, Santa Clara Univ. CS1: chr, jeh, & tmh@cs.rit.edu