Reputation: 49
Is there anyway that I can run only part of the code which I select, instead of Ctrl + F11 and execute all?
Upvotes: 3
Views: 5798
Reputation: 1
You can absolutely run part of your code (in Eclipse). Just use Shift + click to select the parts you do not want to run, and press Ctrl + / to comment out huge bits of code quickly.
To uncomment, make sure you select continuous sections of vertical //
's, and then use the same Ctrl + / command to quickly get rid of all the //
's.
Note: if you press Shift + Ctrl + / with code selected, you will get the "block comment" (`/* code not running */"-type). Use the same keys to undo it, Shift + Ctrl + /.
For me, it is less easy to locate those quickly versus the massive vertical line of //
's
Upvotes: 0
Reputation: 124
In Eclipse you can create a "Scrapbook Page" to test pieces of codes.
In Eclipse go to:
File -> New -> Scrapbook Page -> "MyScrapbook"
Eclipse will create a file "MyScrapbook.jpage"
Write the code in the file, don't create class or main.
Select the piece of code you have wrote and want to run, and press CTRL+U
Upvotes: 1
Reputation: 11
You can easily test a part of your code through a junit test.
You probably need to mock the database calls
Upvotes: 1
Reputation: 2048
If you just want to test a method without any context, you could try using the groovy console and copy / paste there the code you want to "test". You will be able to run it and "test" it.
A link to it : http://www.vogella.com/tutorials/Groovy/article.html
Otherwise the only way to do it is to go through traditional debug mode.
Hope it helps !
Upvotes: 0