0

I can't make any change in src code. this private method is getting called in public method. i have seen similar question on stack (Using Mockito to mock a local variable of a method) but didn't get a satisfactory answer.I hope i get answer through this question.Just a want to remind that i am not allowed to change src code.

  • 2
    Private things are private and *shouldn't* be unit-tested directly. Test the externally-facing functionality of the object. – David May 21 '20 at 13:19
  • Why do you need to test that variable? Do you want to perhaps observe which value it contains when the method is called? – fpezzini May 21 '20 at 13:19
  • in that src code they are trying to access an attribute which is not set their. maybe they are getting it from where else. But right now i want that attribute to set. Because of it I am getting parseEception. that's why i am trying to set that attribute. @fpezzini – Supriya Chougule May 21 '20 at 14:53
  • You don't have many options here. The consensus is that you do not unit test private methods, instead you test the public methods which are the ones visible to the world. That said, if that variable takes its value from an object passed in as a parameter to the method, you can mock that object and mock the return method. ex: String name = person.getName(); But that will only work if you can call the public method with that mocked person and that public method in turn call that private method with the same person as a parameter. – fpezzini May 21 '20 at 15:25
  • that object we can't pass. because it's local variable. – Supriya Chougule May 21 '20 at 15:38

0 Answers0