Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - When I create a JUnit Suite, the list of test classes is empty. Why?

I have a package with 4 test classes. I want to make a JUnit Test Suite. So in Eclipse, I right click my package and do New > Other > JUnit Test Suite

The wizard has a warning that, "Warning: No test classes selected" and the list of Test Classes to include in suite: is empty.

I'm not sure why. I have several *Test.java classes with public methods annotated with @Test. I created these through the JUnit Test Case wizard...

I saw some code on other Stack Overflow answers that I could use to create a Test Suite, but why isn't it working in the IDE?

Should I even bother with a Test Suite? It seems like I can just right click the package and Run As > JUnit Test.

like image 686
Jess Avatar asked Feb 15 '13 19:02

Jess


People also ask

Why does Eclipse not show JUnit?

That kind of J icon filled to a "bubble" means that Eclipse doesn't recognize your project as a Java project, and therefore doesn't provide Java options such as Run as JUnit. Try reimporting the project as a Java Project.

Why is JUnit not working?

The error occurs because the JUnit library has not been configured for the project, but can be resolved using the following steps. 1. Right click on the Java project and select Build Path > Configure Build Path.

How do I change JUnit settings in Eclipse?

Open eclipse → right click on project and click on property > Build Path > Configure Build Path and add the junit-4.10. jar in the libraries using the button Add External Jar. We assume that your Eclipse has inbuilt JUnit plugin.


3 Answers

Did you select the right package in the New -> Other > JUnit Test Suite menu ? By selecting a package with the "Browse..." button, you should see your test classes.

You can run all the tests directly with Run As > JUnit Test on the project but if you have many test classes it is recommended to use a Test Suite to regroup them (ex: slower tests, tests for a certain part of the program, etc.).

Take a look at this post to learn more about JUnit tests grouping.

like image 187
Simon Avatar answered Sep 22 '22 23:09

Simon


Yeah, don't bother with Suites.

You can select the project and run it as a junit test. Eclipse will find all the tests and run them

like image 43
Will Avatar answered Sep 26 '22 23:09

Will


Same happened to me and the explanation is quite simple: you've written your tests using JUnit Jupiter.

enter image description here

However, JUnit Test Suite Wizard let's you pick only these 2 types of suites: JUnit3 or JUnit4.

enter image description here

Refactoring your tests to comply JUnit3 or JUnit4 will make them visible in JUnit Test Suite wizard.

like image 20
Aleksandar Belic Avatar answered Sep 22 '22 23:09

Aleksandar Belic