How to illuminate methods of inner classes?

I am facing a problem how to cover the methods of my inner classes. I have a small GUI (swing) application with a few buttons and defined action listeners as inner classes. Now I want to write tests for each of the action listener methods defined in these inner classes, but when I create a new JUnit using Eclipse, I have no way to cover the methods of the inner classes, but the only public methods of the class where these numbers are defined. Please advice.

+2


source to share


4 answers


Conceptually, internal methods are not usually tested with unit tests, as they are considered an implementation detail. You should test the behavior of your class by checking its public methods.

That said ... http://www.artima.com/suiterunner/private.html



I'm not sure why you need inner classes ... Are they not used anywhere? Why not just make them public lessons outside of your main class?

+9


source


This means your code is not being tested. Move your logic to separate classes and test them. (For example, they can be private to packages so that they are still inaccessible to the outside world)



If your inner classes are logically intrinsic - that is, they represent the inner functioning of your class - don't unit test them, unit-test methods of the parent class.

+2


source


An instance of an inner class can only be instantiated by its outer class. You should write wrapper functions in the outer class or make the inner class normal.

0


source


AFAIK, GUI components are tricky to unit test. If you really want to test them, perhaps you can inject the boolean code into methods in the outer class and make a method call in the inner class for the action. If your inner class actions are GUI updates, I'm not sure how you can effectively test them.

0


source







All Articles