0

Can we unit test a public method which calls a private class which is extending abstract class using Mockito?

this is the method that needs to be tested i am not sure how to proceed i am need to Junit

Sneha
  • 45
  • 5
  • 5
    Did you try it yourself before asking? Do you have a code sample which reproduces your problem that you can add to your question? – Laf Jun 23 '16 at 14:55
  • Extending abstract class do not matter. You can test the methods written inside class as well as inherited methods. If you are testing private method , you may want to look into powermock . Short answer : Yes. – Jimmy Jun 23 '16 at 14:59
  • Alternatively, the Reflection API is good for testing fields and methods that are not visible. http://stackoverflow.com/questions/34571/how-to-test-a-class-that-has-private-methods-fields-or-inner-classes – Hen Jun 23 '16 at 15:12
  • I have put up the sample code ..I need to basically test the execute method of SWT handler which is accessing the public constructor and a public method in private class. – Sneha Jun 23 '16 at 15:40
  • I'm not sur to understand, but the private method will be tested if it is called... if you want to mock a private method maybe you need Powermock. – Mr_Thorynque Jun 23 '16 at 15:44
  • I apologise i have a question does mocking private class work same as mocking private methods? ....we cannot use powermock is there any other way ?...we mock our private methods by actually passing the variables returned from the private method without using power mock – Sneha Jun 23 '16 at 15:48
  • I made the class package private and tested the code i could – Sneha Jul 07 '16 at 21:37

0 Answers0