Running a single JUnit test in Eclipse

后端 未结 13 511
面向向阳花
面向向阳花 2020-11-27 15:05

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

相关标签:
13条回答
  • 2020-11-27 15:31

    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.

    0 讨论(0)
  • 2020-11-27 15:35

    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)

    0 讨论(0)
  • 2020-11-27 15:40

    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.

    0 讨论(0)
  • 2020-11-27 15:40

    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.

    0 讨论(0)
  • 2020-11-27 15:41

    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.

    0 讨论(0)
  • 2020-11-27 15:43

    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.

    0 讨论(0)
提交回复
热议问题