I have some abstract class and some classes that inheritance from it. I want to make JUNIT tester for it. I tried use reflect on the sub classes but in this way I cant see the private variables in the absract class. how can I get to, Or maybe I can create instance of the abstract class for this?
            Asked
            
        
        
            Active
            
        
            Viewed 169 times
        
    2
            
            
        - 
                    By definition it's impossible to create an instance of an abstract class. – PM 77-1 Apr 10 '14 at 01:53
 - 
                    I understand this. but also their is a way to see private variables. How can I go into the this abstarct class variables? – Alon Apr 10 '14 at 01:57
 - 
                    1[What's the proper way to test a class with private methods using JUnit?](http://stackoverflow.com/questions/34571/whats-the-proper-way-to-test-a-class-with-private-methods-using-junit) explains how to use `setAccessible` which works for fields as well as methods. – Mike Samuel Apr 10 '14 at 01:59
 
1 Answers
2
            To see all fields of a class use Class.getDeclaredFields()
        Evgeniy Dorofeev
        
- 133,369
 - 30
 - 199
 - 275
 
- 
                    And to test if the field is private or not, you can use `Field.getModifiers()`. – roll1987 Apr 10 '14 at 02:39