Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all @Test methods in the Eclipse?

I am using Selenium tool and Page Object Model. Currently each page has x number of test cases.

Eg. Login Page (Login Page elements) and LoginPageTest (corresponding validation in LoginPage used JUnit @Test method)

Similarly I do have multiple pages.

But to run as a whole, it seems that this is not sufficient. I need to call all the @Test methods in one class. If something fails, if I re-run that, then that only appears in the Junit result tab.

I don't need another one more class to contain all @Test methods, since each validation class has @Test methods. Is there any possibility to list down all the @Test method in JUnit? Can I run whatever the method I want to run?

like image 782
ChanGan Avatar asked Sep 30 '16 05:09

ChanGan


1 Answers

Finding test methods in Eclipse

Assuming you are using JUnit 4 and your test methods are annotated with @Test, select the @Test annotation and look for its references by pressing Ctrl + Shift + G.

The Search view should be displayed with a list of classes that contain @Test annotated methods. Then, in the Search view, click the Expand All button ( Expand All button icon ) to show all the test methods

Running test methods

To run a particular test, rigth click on the test method signature (also works on the editor) and run it as a JUnit test.

If you prefer the shortcut, use Alt + Shift + X and then T. To debug, use Alt + Shift + D and then T.

Running multiple test methods

You can run multiple test methods from a project, source folder or package. To do it, right click on the project, source folder or package and then run it as a JUnit test.

Alternatives

AFAIK, that's all you can do to display and run JUnit tests in Eclipse. If you are open to use IntelliJ IDEA, there are some cool features available out-of-the-box that you can use to find JUnit test methods.

like image 167
cassiomolin Avatar answered Sep 28 '22 14:09

cassiomolin