2

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?

ROMANIA_engineer
  • 51,252
  • 26
  • 196
  • 186
Alon
  • 2,854
  • 6
  • 25
  • 45
  • 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 Answers1

2

To see all fields of a class use Class.getDeclaredFields()

Evgeniy Dorofeev
  • 129,181
  • 28
  • 195
  • 266