Lecture 9 Testing Object Oriented Programs

Lecture 9 Testing Object Oriented Programs - Testing Object...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Testing Object Oriented Programs CSE 111 01/08/11 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Traditional Stages in Testing Unit testing Test individual classes or small groups of classes during development Integration testing Test larger groups of classes and subsystems System testing Test the whole system. Use test scripts that describe a sequence of user-program interactions and expected resulting behavior 01/08/11
Background image of page 2
Traditional Testing (and Analysis) Methods Functional or black box testing: test with normal and oddball cases. normal: expected functionality oddball: invalid inputs, empty arrays, etc. Coverage: makes sure all the program (e.g. branches, variables and data structures) has been used on a test Code reading: read the code, mentally simulating what it is supposed to be doing 01/08/11 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Specific Object-Oriented Techniques Self-testing classes Test case classes Stubs, drivers and mock objects Class design features that facilitate testing i.e. design for testability Subsystem testing strategy for 3-tier system Inheritance and abstract test cases 01/08/11 4
Background image of page 4
5 Self-Testing Classes Each class has a main method that is used for testing Except for the class with the “real” main method that is used to start the program Testing a class A with its main() method: Create an instance of the class A Call its methods, checking the results Report results of tests 01/08/11
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Test Case Class Special class T for testing another class or classes (the CUT = class under test) T contains a collection of special test and verify methods main() method in test case class T Creates an instance of the CUT, performs initialization, runs its test methods 01/08/11
Background image of page 6
7 Tests and Test Suites Test = TestCase or TestSuite TestSuite = Collection of Tests TestCase TestSuite TestCase TestSuite TestSuite TestCase TestCase TestCase 01/08/11
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 TestRunners Run the tests for a set of classes Needs to be able to know which methods in a class are the test methods it needs to run If test methods use special assert statements to check results, then results are automatically reported 01/08/11
Background image of page 8
J-Unit Originally was far more complex and flexible, but was difficult to use JUnit 4 Special annotation is used to indicate which method is a test method may be in the CUT or in separate test case classes Supports specialized kinds of assert statements and other advanced, simplifying features 01/08/11 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sample JUnit Test Case import static org.junit.Assert.assertEquals; public class AdditionTest { private int x = 1; private int y = 1; @Test public void addition() { int z = x + y; assertEquals(2, z); } } 01/08/11 10
Background image of page 10
Stubs and Drivers Suppose we want to test a class C which supports some responsibility, but is called by other classes, and calls classes itself How to isolate C during testing?
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/07/2011 for the course CSE 111 taught by Professor Howden during the Spring '07 term at UCSD.

Page1 / 40

Lecture 9 Testing Object Oriented Programs - Testing Object...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online