SDSU CS 580 Client-Server Programming
Fall Semester, 2000
Testing Hidden Methods
Previous    Lecture Notes Index    Next    
© 2000, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 04-Oct-00

Contents of Doc 11, Testing Hidden Methods


References
XP mailing list

Inner Class lecture notes at: http://www.eli.sdsu.edu/courses/fall98/cs596/notes/nested/nested.html


Doc 11, Testing Hidden Methods Slide # 2
How NASA Navigates Space Craft

  1. Send the craft in the general direction of the target
  2. As you get closer to the target, adjust the craft's direction
  3. Repeat 2 until you reach the target





Doc 11, Testing Hidden Methods Slide # 3

Testing and Hidden Methods/State


Issues:




Doc 11, Testing Hidden Methods Slide # 4
Testing Hidden Methods One Position Don't Do it

Pro:



Con:



Doc 11, Testing Hidden Methods Slide # 5

How to Test Hidden Methods Directly?

Method 1: Relax the protection level


In Java one can



Pro:



Con:



Doc 11, Testing Hidden Methods Slide # 6
How to Test Hidden Methods Directly?

Method 2: Use inner classes


import junit.framework.TestCase;
public class Foo {
    private int value;
    private void bar() {
        value = 10;
    }
    public static class FooTest extends TestCase {
        public FooTest(String name) {
            super(name );
        }
        public void testBar() {
            Foo a = new Foo();
            a.bar();
            assert( 10 == a.value );
        }
    }
}

Pro:

Con:


Doc 11, Testing Hidden Methods Slide # 7
How to Test Hidden Methods Directly?

Method 3: Use reflection


Pro:

Con:

See http://www.eli.sdsu.edu/courses/fall98/cs596/notes/reflection/reflection.html for more information about reflection



Copyright ©, All rights reserved.
2000 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 04-Oct-00    Next