KUNWAR ITECH7409Tutorials 09

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

ITECH7409 Software Testing

Tutorial 9

This Tutorial sheet comprise two parts: Review Questions and Further Exercises. The Review Questions
have been designed as a revision exercise covering some of the main points covered in the lectures.
The Further Exercises are generally exploratory in nature being extensions of the lecture materials.
Students will benefit if they discuss their solutions to both parts in small groups. All questions should
be attempted and it is expected that students may need to complete some of the tutorial in their own
time. Note: some of the questions in Further Exercises may require the use of a computer with some
specific software and internet connection.

As the final exam will draw material from lectures, tutorials and assignments, students are strongly
advised to work consistently and to attend both lectures and tutorials.

Review Questions

1. Broadly speaking, what are some of the benefits of an object-oriented approach when developing a
system?
Some of the benefits of an object-oriented approach are:
The classes,objects, methods and messages supports highly cohesive units that contain both data and processes. It
leds to better communication between user and analyst and reusable objects.
Encapsulation and information hiding supports loosely coupled units which leads to reusable objects, fewer ripple
effects from changes within an object or in the system itself
Inheritance allows us to use lasses as standard templates from which other classes can be built which leads to less
redundancy,faster creation on new classes and ease in supporting exceptions
Polymorphism and dynamic binding supports minimal messaging that is interpreted by objects themselves which
leads to simpler programming of events and ease in replacing or changing objects in a system.

2. Broadly speaking, how is testing in an object-oriented approach different to testing in a traditional software
development?
Object oriented system are a collection of classes that work individually and together in a system. Every
class has its own characteristics and behaviours.Testing focuses on the class being a unit and intra-class
testing of methods and interfaces to data is similar to classical unit testing. The inter class testing including
inheritance, polymorphism and dynamic binding of objects spans integration and system testing.

CRICOS Provider No. 00103D Page 1 of 6


3. In an object-oriented development, why is it necessary to use drivers and stubs in testing?
In object-oriented development, encapsulation and data hiding within a class creates problems for testers wishing
to access various data items. So, there is a heavy reliance on drivers and stubs. Drivers can be used to test
operations at lowest level and for testing whole groups of classes and to replace the user interface so that tests of
system functionality can be conducted prior to implementation of the actual interface.
Stubs can be used in situation in which collaboration between classes is required but one or more of the
collaborating classes has not been fully implemented.

4. When testing classes what difficulties does inheritance cause?


Methods in super and child classes are required to be tested thoroughly. The testing is straight forwar in super class
but is complicated for the child. Inherited methods do not need to be retested, overridden methods and new
methods should be tested thoroughly.

5. What type of object-oriented models are useful for a guiding a tester?


The different use of case diagrams, case description, activity like state and sequence diagrams and class
diagrams are object-oriented models that are useful for a guiding a tester.

6. What is thread-based testing in object-oriented systems?


Thread based testing integrates a set of classes required to respond to one input or event in a system. Each thread is
integrated and tested individually and regression testing is applied to ensure that no side effects occur.

7. Why is exception handling an issue for testers in object-oriented developments?


Exception handling is an issue because it creates a implicit control flows which can be handled by different handlers
which requires each path to be tested.

Further exercises

8. Examine the inheritance hierarchy for classes Person, Student, Tutor.


a) What is the driver program shown in the diagram?
The driver program shows TestEveryOne

CRICOS Provider No. 00103D Page 2 of 6


Describe in detail how you will test class Person and class Tutor.
The Testing Class person would be used by driver class TestEveryOne to create several
instances of person and call methods within a class
Testing class tutor would use driver class to create several instances of class tutor.

9. Examine the class diagram for class TutoringSystem that creates ArrayLists of tutors and students.
What approach would you take to test this class?
The testing class TutoringSystem initially needs a driver class TestTutoring System for the creation of
TutoringSystem. The testing for class Tutor and class Student and class person would need to have taken place
so that the methods of this class can be tested. Else, stubs would be required to be create but this would be
more work than writing and testing the actual classes.

CRICOS Provider No. 00103D Page 3 of 6


10. Exception handling in Java programs needs special consideration as exceptions create implicit control
flows that may be handled by different handlers. Each path needs to be tested.
Examine the Java program for class ZeroCommandLine that accepts two ints from the command
line and then prints out the division of the first int by the second.

//*****************************************************
// ZeroComandLine.java
// revised Lewis & Loftus program, an introduction to exceptions
//*****************************************************
public class ZeroCommandLine
{ public static void main (String [ ] args)
{ int numerator ;
int denominator ;

numerator = Integer.parseInt( args [0]) ;


denominator = Integer.parseInt ( args [1] );
System.out.println ( "The division is " + numerator/denominator ) ;
} // end main } // end class
Here is the first of the program. All appears well.

Here are the next four tests.

CRICOS Provider No. 00103D Page 4 of 6


The test results were reported to the developer, who added a set of exceptions to the program as
shown.

//**************************** *****************************
// ZeroCommandLineTry.java
//************************************************************
public class ZeroCommandLineTry .
{ public static void main (String [ ] args)
{ int numerator ;
int denominator ;

try
{ numerator = Integer.parseInt( args [0]) ;
denominator = Integer.parseInt ( args
[1] );
System.out.println ( "The division is " + numerator/denominator ) ;
}

catch ( ArithmeticException exception1 )


{ System.out.println ( "Division by 0 is undefined" ) ;
}
catch ( NumberFormatException exception2 )
{ System.out.println ( "Input numbers must be integers" ) ;
}
catch ( ArrayIndexOutOfBoundsException exception3 )
{ System.out.println("there are not enough arguments on the command line");
}
} // end main
}//
end class

Now desk check the program with the same test data as previously. What are the expected results?

CRICOS Provider No. 00103D Page 5 of 6


CRICOS Provider No. 00103D Page 6 of 6

You might also like