Protected Junit Method

I am wondering how you can work with a protected method in Junit.

Assuming I want to test class A, which has a protected member and constructor. I realized that for testing class A, I have to write another ATest class that can extend TestCase (this should be mandatory in Junit3). Since I want to test a protected method and because A has a protected constructor, my test class ATest also needs to extend the class A where this method is implemented in order to be able to create this class and access this method.

maybe double inheritance from both classes is a good solution?

PS I already knew that in Junit 4 you can avoid inheritance from TestCase.

+8
java junit junit4 junit3
source share
2 answers

To access A protected members, you can simply put A and ATest in the same package.

+17
source share

Java does not allow multiple inheritance of an implementation. You can implement several interfaces.

I would rather use reflection to get testing methods that I don't want to know about. It works for private methods.

+1
source share

All Articles