Is it possible to inspect local variables of a method in JMockit?
Source
void foo(){
boolean isPresent = false;
/// ... something here sets isPresent
}
Test
can I check the value of isPresent at the end of call of foo() using JMockit?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rather than trying to do some obscure mocking mechanism. Try refactoring the code to something that you can test:
Also, consider this. If the variable’s value never escapes the method and does not cause some other effect (which should be testable), why try to test it? Or why is it even there? Testing that a method scope variable’s value is x has no value. Testing that the method resulted in y because the variable was x has value.