In a JUnit test case with multiple @Test annotations, how does one selectively run tests ?
For e.g., from the following code, how does one run just one test method ?
@Test
public void testHelloEmpty()
{
assertEquals(h.getName(),"");
assertEquals(h.getMessage(),"Hello!");
}
@Test
public void testHelloWorld()
{
// h.setName("World");
assertEquals(h.getName(),"World");
assertEquals(h.getMessage(),"Hello World!");
}
I have tried to just highlight one @Test method and tried to run it, but it doesn't work that way.
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.
Yes, You can. Show activity on this post. JUnit Toolbox provides JUnit runners for parallel execution of tests.
For running a single test case in Eclipse (as per your last comment):
It seems that now days (Eclispse 4.4.0) this can be done easily.
If you place the caret at the head of the definition of a test case method, issue the Run or Debug command (menu or F11 or Ctrl+F11), then the JUnit plugin runs only that test case.
(If you on the other hand place the caret in the body of a method then all the test cases in that class are run.)
Some more tips for running JUnit tests:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With