score:0

for me, it also does not work in eclipse 3.4.2 , although it worked in the previous releases (i have tried running single method from package explorer and single junit test from junit view)

score:0

i agree with the point about 3.4.2 no longer working the way it did in previous versions. before you could right-click on a single test in a group of tests from the junit view and execute just that test. in the latest version it insists on always running all of them. granted, the view does run the test you clicked on first and dumps the rest in a rollup called "unrooted tests". if anyone figures this out i'd like to know how to get around it.

score:0

reading some of the comments here, it seems you might be interested in running the tests for the code you change as you change it, without losing focus on the code you are working on. there's an eclipse plugin for doing just that. see infinitest.

score:1

if you have many tests in more than one file, and you want to run only the tests in a particular file, you could right click that file, and select run as -> junit test. now, if you want to run only one test, contained in a file with many tests, my guess is (i dont have eclipse installed here) that the outline view will list all test methods for a file, and you will probably be able to right click a single test method and execute it as a junit test.

hope it helps.

score:2

i had the same problem others have had using eclipse 3.4.1 and junit 4 test runner -- couldn't run single test. but i found a suggestion somewhere else that resolved the problem. my test class was still extending junit.framework.testcase. when i stopped extending testcase, everything worked fine and i was able to run single junit tests with the junit 4 test runner. of course, i needed to junit 4 annotations use static imports for the assert methods, but i had already done that -- i had just not removed the testcase inheritance.

score:3

right click somewhere on the test method name in the file and select "run" -> "junit test". i do it all the time with kepler and junit 4.

score:3

to run only one test method.
in the (package explorer or project explorer) unfold the class. it should show you all methods. right click on the one method you want to run, then select run as -> junit from the context menu.
enter image description here

score:9

don't use strg+f11 but the hotkey alt+shift+x -> t.
then eclipse will execute the current open file as a junit test. the green play button will only run the last chosen run configuration.

for me, it works well with alt+shift+x -> t.

score:9

i'll add to the others by including a highly productive keyboard only way that allows you to debug a single unit test (method).

move your cursor to the method name by using either

  • ctrl+shift+up or
  • ctrl+shift+down or
  • ctrl+o then type the name of the method

once your cursor is on the method name (or right before it):

  • alt+shift+d -> t (debug)
  • alt+shift+x -> t (run)

after you run the test you can go back to where your cursor was by doing:

alt+back

you almost get repl like behavior by:

ctrl+shift+up and alt+shift+x -> t and alt+back

you can also quickly set a breakpoint:

ctrl+shift+b

score:13

in eclipse 3.5, you can get around this by changing the test runner to junit 3. this will only work for junit 3 tests, not junit 4 tests. you can change the test runner by doing the following:

  1. right click on one of the test methods in the outline explorer
  2. select run as -> run configurations
  3. on the 'test' tab, select 'run a single test'
  4. in the test runner dropdown, select 'junit 3'

it may work in other versions as well.

score:13

this is possible in eclipse indigo with junit 4.8.2. you right click the method you want to unit test individually in the outline pane, and select run as -> junit test.

you can even selectively right click a test method name in the source editor and select run as -> junit test.

score:27

fastest way i know of:

  1. press ctrl+shift+ (moves cursor to current method declaration),
  2. press alt+shift+x (or d for debug) then press t (hotkey for "run junit test"),
  3. check test result,
  4. press alt+ to get back to the line of code you were before.

if you want to run all tests, you can skip steps 1 & 4.

score:97

in the package explorer unfold the class. it should show you all methods. right click on the one method you want to run, then select run as -> junit from the context menu (just tested with eclipse 3.4.1). also selecting "run" on a single entry in the junit-results view to re-run a test works in the same way.


Related Query

More Query from same tag