57

Using Eclipse, when debugging is it possible to change the value of variables during runtime of a project for testing purposes.

For example, say I have a method that returns the number 5 but for testing purposes i want to output 10 instead. This isn't the problem I'm facing its a little more complex but its just to get my idea across.

5 Answers 5

73

You should be able to set a break-point, go into debug mode, open the variables views and here change the content of the variables.

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

For any other new Eclipse users: get variables view with Window -> Show View -> Variables
It says type doesn't match when trying to set Boolean. tried both true and new Boolean(true) and Boolean.TRUE both say Type Mismatch
@Jackie, I can expand my Boolean variable and change the value field from true to false in a dropdown menu. I can also right-click on the variable and enter a whole new expression for it, and entering Boolean.FALSE works fine for me. Post a new question, including a small program and version of Eclipse and a screen shot of your situation and I can help further.
21

You can access variables through the Variables view. There you can right click on any variable and select "Change value ...".


Resources :

Comments

7

... and you can do much, much more:-) Just to give you and idea.
You may change the code during debug which is hot swapped and is effectively changed (recompiled) in given debug session. You may run given method run (e.g. after catching breakpoint) few times without rerunning debug -> use drop to frame feature on method stack.

2 Comments

this sounds interesting..could you explain what drop to frame is?
It reruns given method on the stack. So it is invoked as at the first time with same parameters. see it here vasanth.in/2004/06/08/eclipse-tip-rewind-during-debugging
5

After you have changed the code you have to save it (cntrl-S) to make it effective. You will see your running application respond to the code-change after the cntrl-S

I hope this works for you. it took me some time to figure this out.

Comments

2

Run your application in debug mode then go to variables window. select the parameter then change values according to your requirements. then save (ctrl+s). and go ahead with your changes. Hope this will help.

If variables window is missing. then goto eclipse window->show views->variables

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.