Posted By:
David_Bates
Posted On:
Saturday, March 1, 2003 08:48 AM
OK. I'm writing a class 'MyClass' which exposes a number of public methods: 'pub1()', 'pub2()' and 'pub3()'. However, all of these methods use a protected helper method 'proHelper()'. How can I test the protected helper methods using JUnit? I don't want to put the JUnit test class in the same package as the class (I consider that bad form. The test classes should be in a mirror hierarchy to the application packages). I have a couple of ideas, the best of which is: Create the test class called 'TestMyClass' in the test hierarchy. This class contains an inner class 'pubMyClass' which is a subclass of 'MyClass'. This class overrides the protected method: public void proH
More>>
OK. I'm writing a class 'MyClass' which exposes a number of public methods: 'pub1()', 'pub2()' and 'pub3()'. However, all of these methods use a protected helper method 'proHelper()'. How can I test the protected helper methods using JUnit? I don't want to put the JUnit test class in the same package as the class (I consider that bad form. The test classes should be in a mirror hierarchy to the application packages).
I have a couple of ideas, the best of which is:
Create the test class called 'TestMyClass' in the test hierarchy. This class contains an inner class 'pubMyClass' which is a subclass of 'MyClass'. This class overrides the protected method:
public void proHelper() {
super.proHelper();
}
The method 'proHelper()' is now visible to the class 'TestMyClass'.
If anyone has any thoughts on this, I'd like to hear them. Also, I'd be interested to hear if anyone has any bright ideas about testing
private
helper methods.
Cheers,
David.
<<Less