tags:

views:

1872

answers:

8

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.

+11  A: 

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.

ShiDoiSi
A: 

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.

Tom
+3  A: 

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.

furtelwart
A: 

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)

Running a single method/test from the Package Explorer works just fine for me in Eclipse 3.4.2.
ShiDoiSi
A: 

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.

raiglstorfer
+2  A: 

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.

lrussell
Good call! Changing "Test Runner" to "JUnit 3" in the run configurations dialog worked for me in Eclipse 3.6.0 (Helios). Now I can run a single method in a JUnit test.FWIW, I've never had a problem running individual JUnit 3 or 4 test *classes*.
Adam Monsen
A: 

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.

ghirschhorn
A: 

the outline view way worked in Oracle Workshop for WebLogic that's built on eclipse

tejas