Home > Blockchain >  Get a value of a local variable from a void function using mockito
Get a value of a local variable from a void function using mockito

Time:05-05

I have a method like below:

public void process {
   ArrayList<String> data = new ArrayList<>();
   ...
   ...
}

data is a local variable, the value of which I want to access after calling myObject.process() inside the test function. Is there any way I can do that?

CodePudding user response:

Mockito cannot access a local variable which is created by your code. The only way to test the code is to check whether something else is being effected by that variable and verify that change. This answer should help you out.
https://stackoverflow.com/a/30188745/17052051

  • Related