Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8 Testing a class. This chapter discusses n Testing in general. n Testing a single class. n Test plans. n Building a test system.

Similar presentations


Presentation on theme: "Chapter 8 Testing a class. This chapter discusses n Testing in general. n Testing a single class. n Test plans. n Building a test system."— Presentation transcript:

1 Chapter 8 Testing a class

2 This chapter discusses n Testing in general. n Testing a single class. n Test plans. n Building a test system.

3 Testing n Testing is an activity whose goal is to determine if the implementation is correct. n A successful test is one that reveals some previously undiscovered error.

4 Testing Phases n Test activities are determined and test data selected. n The test is conducted and test results are compared with expected results.

5 Test design n Begins with an analysis of: u The functional specifications of the system. u The ways in which the system will be used (referred to as use cases). n Testing based on these considerations is referred to as black box testing.

6 Black Box testing n The test designer ignores the internal structure of the implementation in developing the test. n The expected external behavior of the system drives the selection of test activities and data. n The system is treated as a black box whose behavior can be observed, but whose internal structure cannot.

7 Test case n Test cases are defined by: u A statement of case objectives. u The data set for the case. u The expected results.

8 Equivalency groups n Test cases are chosen from each equivalency group. n Particular attention is paid to data that lie on group boundaries.

9 Test plan n A test plan is a document that describes the test cases giving the purpose of each case, the data values to be used, and the expected results. n Test design should be carried out concurrently with system development. n Developing and refining test cases based on the implementation of the system is referred to as white box testing. n A test plan can be based on class specifications only.

10 Test system n Test systems allow us to interact with the object we want to test. n The test system will let us create the object to be tested and then act as a client of the object.

11 Testing Counter n Class specifications: public class Counter A simple integer counter. public Counter () Create a new Counter initialized to 0. public int count () The current count. ensure: this.count() >= 0 public void reset () Reset this Counter to 0. public void increment () Increment the count by 1. public void decrement () Decrement the count by 1. If the count is 0, it is not decremented.

12 Possible system Enter number denoting action to perform: Increment Decrement Reset Create a new Counter...4 Exit Enter choice. 1 The current count is: 1 Enter number denoting action to perform: Increment Decrement Reset Create a new Counter...4 Exit Enter choice. 1 The current count is: 2...

13 Building a test system n The test system will be composed of two objects: u A Counter to be tested. u A test driver to invoke the Counters methods. n The test driver prompts the user with a menu, gets input from the user, and provides output in the form of the count.

14 CounterTUI n TUI -> Textual User Interface.

15 Basic input/output n Basic I/O consists of reading from standard input (keyboard) and writing to standard output (monitor).

16 Basic input/output (cont.) n We will use methods provided by the authors (OOJ.basicIO.BasicFileWriter, OOJ.basicIO.BasicFileReader). public BasicFileWriter () Create a BasicFileWriter attached to standard output. public void displayLine (String line) Write the specified line to standard output. public BasicFileReader () Create a BasicFileReader attached to standard input. public void readInt() Reads a new int from standard input. public int lastInt() Returns the int read by readInt(). public void readline () Read rest of line from standard input.

17 CounterTUI specifications public class CounterTUI A text-based test driver for the class Counter. public CounterTUI () Create a new test driver with a Counter to test. public void start () Conduct the test.

18 CounterTUI implementation public class CounterTUI { public CounterTUI () { input = new OOJ.basicIO.BasicFileReader(); output = new OOJ.basicIO.BasicFileWriter(); counter = new Counter(); … } … private OOJ.basicIO.BasicFileReader input; private OOJ.basicIO.BasicFileWriter output; private Counter counter; }

19 CounterTUI implementation (cont.) n If we look at what happens when the test is conducted, we see that the following sequence of actions are repeated over and over: u Display menu to the user and prompt the user for input. u Get the users input. u Perform requested action. u Display results.

20 CounterTUI implementation (cont.) n We define an instance variable to hold the users choice. private int choice; // the users most // recent choice n The local methods we will create are specified as follows. private void displayMenuPrompt () Display the menu to the user. private void getChoice () Get the users choice. private void executeChoice () Perform the action indicated by this.choice, and display the results to the user.

21 While loop n A while loop continues to perform an action as long as a condition is true. The while statement is composed of a condition (a boolean expression) and another statement, the body. n syntax: while ( condition ) body

22

23

24

25 Implementation n main method: the top-level method that initiates execution of a system. n Although the main method is defined in a class, it is really outside the object-oriented paradigm. n Its only purpose should be to create the top level objects and get the system started.

26 Implementation (cont.) /** * A test system for the class Counter. */ public class CounterTest { /** * Create the user interface, start * the system. */ public static void main (String[] argv) { CounterTUI theInterface = new CounterTUI(); theInterface.start(); }

27 Test plan action expected comment increment 1 increment from initial state increment 2 sequence of increments increment 3 increment 4 decrement 3 sequence of decrements decrement 2 increment 3 increment follows decrement reset 0 increment 1 increment follows reset decrement 0 decrement 0 decrement 0 count reset 0 decrement 0 decrement follows reset create 0 initial state decrement 0 decrement from initial state

28 Weve covered n The process of testing. n Test systems. n Text-based user interface. n read-process-write loop. n while loops. n main method.

29 Glossary


Download ppt "Chapter 8 Testing a class. This chapter discusses n Testing in general. n Testing a single class. n Test plans. n Building a test system."

Similar presentations


Ads by Google