Eclipse cannot run JUnit 5 test cases in JUnit suite? - eclipse

I've got working junit test cases I'd like to run in an Eclipse test suite. However, Eclipse only seems to have test suite support for JUnit 4 and 3.
It seems my options are to either either downgrade my test cases (which I'm unsure how to do) or upgrade the test suites as well (which I can't seem to find an option for).
Any help?
EDIT: For clarity, I'm working on the latest Eclipse Photon version, just downloaded it two days ago.

With a plain Photon (Java Developers flavour) install, follow these steps to get a working simple eclipse project with a JUnit5 test and a suite containing this test.
On project creation or in the project properties, add JUnit5 as library
Add your tests, run them
Add a test suite (the new Test Suite wizard is lacking the option to create a JUnit5 Suite, you'd need to write it by hand - was that what you were asking?)

In package explorer, do right click on a project and,
Click 'Build Path'
Click 'Add Libraries'
Click on 'JUnit 5' in the list and next, finish.
Then run the tests again.

Related

Eclipse 2019-03 failing to run certain JUnit 4 tests from the Window but not Test suites or run configuration

I have installed Eclipse 2019-03 from both the installer and tar ball. Certain JUnit test will run from a "run as" selection in the window and others will not. The ones that will not run will run:
Test suite that includes the test class
Run -> run configurations
You can also run it from the JUnit view either from a test suite or run it again.
I have tried deleting then adding the code back in then which seems to work but then fails again in future.
I have tried re-installing eclipse and then adding the src and pom to the maven project and the issue is still there.
Any suggestions?
2019-06-28:
It seems there are also issues with this version of eclipse finding the main method in my Main class. Although removing or changing the code did resolve the issue there were a number of other issues croping up. I tried again to resolve this using both a new "run configuration" and run "Java Application". Both fail to find the class. This is a very simple Java 11 maven projet and I do not see why it is having these issues.
At this point I am going to roll back to a previous version of eclipse to see if it is having similar issues with this code.
2019-06-28 NEW:
Rolling back to photon resolved the issues with both running the code and the junit issues.
Version: Photon Release (4.8.0)
Build id: 20180619-1200

how to "debug as maven test" in eclipse (sts)

I have written test cases in JUnit and they are executing fine when I use run as - maven test. But although I put debug points and select debug as - maven test, debugging does not work. I use maven-surefire-plugin. I am running the test cases in eclipse (STS) itself, there is no need for remote debug on an application running in server. These are simple test cases, testing some application code. Help would be much appreciated.
You can run the JUnit test directly in STS also for debugging. So no need to start Maven for that purpose.
Click on the Test Class you would like to debug. Right mouse button -> Debug As -> JUnit shoud do the trick.

Difference between `JUnit Plug-in Test` and `JUnit Test` in eclipse

In the eclipse run command, there are two choices: JUnit Plug-in Test and JUnit Test.
Before, I tried to launch eclipse plugin test (org.eclipse.jdt.ui.tests.refactoring), and I had some issues ( Debugging eclipse unit test code "Test class should have exactly one" and "Workspace is closed" error ).
The issue was that when I tried to launch the debugger with JUnit Test, I got Workspace is closed error.
In eclipse configuration, they have the same workspace.
What is the difference between the two? And especially, how does workspace work for them?
Why I have Workspace is closed error with JUnit Test run? Is it possible to launch eclipse plugin test with JUnit Test?
JUnit Plug-in test is for testing Eclipse plug-ins. It runs a new instance of Eclipse. Then, it runs the tests.
JUnit test is for testing regular Java applications. It runs the tests without launching a new instance of Eclipse.

JUnit plugin integration

Is there a way to integrate in an Eclipse RCP project the JUnit Window? I am planning on creating a test script runner and I want JUnit window to be in my application.
Sure, but not as you expect it. The JUnit view is contributed by org.eclipse.jdt.junit (which you can see by hitting Shift-Alt-F1 with that view being active). So you need to include that as a dependency in your plugin (or in your product definition, if you have one).
The bad news: I have not checked the dependencies for that plugin, and those dependencies will probably take most of the JDT into your application also, which is probably not desired.

Why is Eclipse using JUnit 3 when I have junit-4.3.1.jar in my build path?

I'm using Ganymede on Ubuntu Linux and I have junit-4.3.1.jar in my build path. I click File > New > Java > "JUnit 4 Test Case" when I create a new test, but when it's run, Eclipse appears to be using JUnit 3. I believe this is the case because it's ignoring my annotations.
When I remove all test* methods, JUnit complains "No tests found". If I do the same with another test I already created, JUnit runs fine and finds my test named createTask(). So, it appears to be using JUnit 3 at times, and JUnit 4 at others.
How do I force Eclipse Ganymede to use JUnit 4?
I figured out the answer via this link:
Spring is apparently incompatible with JUnit 4.3.1 when extending AbstractTransactionalSpringDataSourceTest (or whatever it is). So, I upgraded to JUnit 4.6 (b/c 4.5 has issues) and used the annotation-based configuration, and voila, all is well.
Thank you.
I have 2 suggestions that might help. First, in the Run/Debug configuration, Make sure the JUnit 4 test runner is selected. Next, if this is a plugin project, add the junit4 runtime to the project as a dependency (in the dependencies tab).