Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a single JUnit test in Eclipse

Tags:

junit

eclipse

If I have a test suite with multiple tests, when I try to run a single unit test, either from the context menu of the code editor, or from the JUnit view, it seems to insist on always running the entire suite, rather than the single test. Is there a way to disable to change this behavior so that I can ask to to run that, and only that, test.

like image 958
user14128 Avatar asked Mar 14 '09 17:03

user14128


People also ask

How can individual unit test method be executed or debugged?

Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T). If individual tests have no dependencies that prevent them from being run in any order, turn on parallel test execution in the settings menu of the toolbar.


2 Answers

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.

like image 186
Volker Stolz Avatar answered Sep 29 '22 03:09

Volker Stolz


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.

like image 31
schnatterer Avatar answered Sep 29 '22 01:09

schnatterer