160 likes | 269 Views
Design and Method. Testing and Test Harness. Objectives. Set up a test plan for a simple Java class. Distinguish basic from volume test plans for more elaborate Java classes. Draw a (class) diagram for a state to be displayed. Plan a test harness for a given functional interface.
E N D
Design and Method Testing and Test Harness J. B. Wordsworth: J5DAMTTH
Objectives • Set up a test plan for a simple Java class. • Distinguish basic from volume test plans for more elaborate Java classes. • Draw a (class) diagram for a state to be displayed. • Plan a test harness for a given functional interface. • Know what files to submit. J. B. Wordsworth: J5DAMTTH
Class testing • Use the sequence diagrams to determine the collaboration hierarchy . • Test the classes starting at the ends of the hierarchy. • Write a driver for the class to be tested. • Use general methods to develop the driver and the test cases. J. B. Wordsworth: J5DAMTTH
The Paper class • Attributes: • num : an integer • customers : a HashTable, String to null • Constraints: • num is the size of customers. • Methods: • Paper () num, customers := 0, empty. • addOrd (String cn) adds cn to the keys of customers and increases num by 1. • delOrd (String : cn) removes cn from the keys of customers and decreases num by 1. • showOrds () returns an Enumeration of the keys of customers. • getNum () returns num. J. B. Wordsworth: J5DAMTTH
Test plan for Paper • Test scheme: • Paper () • getNum () {0} • addOrd (“Jim”) ; getNum () {1} • addOrd (“Pat”) ; addOrd (“Les”) ; getNum () {3} • delOrd(“Pat”); getNum () {2} • showOrds (); display list; {“Jim”, “Les”; or “Les”, “Jim”} • Documentation: • Test ID, Message, Expected output J. B. Wordsworth: J5DAMTTH
Test plan for Newsagency - basic • Create an initial Newsagency • Exercise the methods that do not change the state • Test ID, Test message, Expected output • Add a customer • Exercise the methods that do not change the state • Add a paper • Exercise the methods that do not change the state • Add an order • Exercise the methods that do not change the state J. B. Wordsworth: J5DAMTTH
Displaying the state State 0..* 0..* Customer details Paper details 1 etc. Customer name 1 1 Address Order details 0..* Paper name J. B. Wordsworth: J5DAMTTH
A state displayed Customers: Jim at The Lodge has orders for: Times Daily Telegraph Jane at 5 The Crescent has orders for: Daily Mail Times CLNH at Cedar Lawn has orders for: Sun Times Papers: Times has 3 copies Daily Mail has 1 copy Daily Telegraph has 1 copy Sun has 1 copy J. B. Wordsworth: J5DAMTTH
Test plan for Newsagency - volume • Create an initial Newsagency. • Set up a more elaborate state with customers, papers, and orders (external file?). • Display the state. • Choose something to test. • While there are things to test: • Exercise a method that needs testing. • Display the state. • Choose something else to test. • Documentation: • Test ID, Message, Expected output, Expected change of state J. B. Wordsworth: J5DAMTTH
Documenting test cases • Test case ID • System configuration being tested • FID function being tested • Initial state • Input values • Expected final state • Actual final state • Expected output • Actual output • Pass or fail? J. B. Wordsworth: J5DAMTTH
Test harness structure • Present one menu item for each FID function. • Add menu items to view/set state. • Program one switch with a case entry for each menu item: • set values in state • accept input arguments • run the function • display outputs and state change. J. B. Wordsworth: J5DAMTTH
Test harness class public class TestHarness { public static void main(String args[]) throws Exception { TestHarness th = new TestHarness(); try { th.run(); } catch (Exception e) { System.out.println(e); } th.quit(); } J. B. Wordsworth: J5DAMTTH
Test harness usage • input from keyboard, output to screen • input from keyboard, output to a file • input from file, output to a file J. B. Wordsworth: J5DAMTTH
Project files • *.java for each back-end class • *.java for state (container class) • Wrapped*.java • FIDo.java (interface) • TestHarness.java • *.dat (to hold the data) J. B. Wordsworth: J5DAMTTH
Summary • Test plans should exercise all the functions and states of a product. • Class testing begins at the bottom of the collaboration hierarchy. • Displays of state before and after a test might need special methods. • A test harness is designed to allow its user to exercise the functions of an interface. J. B. Wordsworth: J5DAMTTH