How do I create a JUnit5 Test Suite in Eclipse? [message #1796712] |
Thu, 18 October 2018 01:22 |
Reinhardt Christiansen Messages: 73 Registered: March 2010 |
Member |
|
|
I'm trying to learn JUnit 5 and how to create test cases and suites in Eclipse after a long absence from Java. I've gotten the hang of creating test cases with JUnit5 but I'm struggling to create the JUnit 5 test suites in Eclipse. It looks simple enough in the documentation but Eclipse is not co-operating.
I'm running Eclipse Oxygen.3a Release(4.7.3a), Build id: 20180405-1200 on Windows 10 and when I click on Help/Update, it tells me there are no updates available. I've been away from Eclipse for a few years too so I've forgotten: does this mean I am fully up-to-date or only that I have the latest update for Oxygen.3a but that it has been superseded by a newer version that I have to install to get all the latest bells and whistles?
The reason I ask is that Eclipse behaves as if JUnit 5 is only partially installed. I've created JUnit 5 test cases but when I try to create a JUnit 5 Test Suite, it only lets me choose between JUnit 3 and 4 - MOST of the time. But last night, I was struggling with it and it actually let me create a JUnit 5 test suite *and* run it successfully. I don't remember exactly how I did it though and every time I try to create a test suite successfully now, I don't get an option for JUnit 5.
I've tried the following:
- looked for YouTube videos on creating JUnit 5 Test Suites but videos were either JUnit 4 or earlier or they only covered creating test cases but not test suites
- looked for documentation online but couldn't find something that showed how to create test suites in Eclipse
- looked in the Eclipse documentation and found info about building test cases but not test suites.
I did find information about how to create Test Suites manually (http://howtodoinjava.com/junit5/junit5-test-suites-examples/) and have imitated that but one of two things happen:
- I get compile errors when I try to run the suite OR
- the suite runs but elapsed time is 0:00 and no tests are listed, which obviously means nothing happened
Here is my AllTests.java:
@RunWith(Suites.class)
@SelectPackages("com.domain.my")
@SuiteClasses({})
public class AllTests {
}
(I'm using Suites.class in the RunWith annotation because I get an error message when I use JUnitPlatform.class, which is what the documentation uses.)
I've structured my project slightly differently than the way recommended in the documentation; I found a good, short video on making test cases and followed his recommendation since he had lots of experience with JUnit 5. I have a regular Java project called Common with a standard src folder containing a package named com.domain.my; beneath it are the classes I want to test. Also directly under the project and therefore parallel to the src folder, I have a source folder called UnitTest. It contains a package called com.domain.my and that package contains my test cases, all of which work fine, and my test suite, AllTests, which is my current problem.
I would be happy to provide more information if you tell me what would help you help me :-)
|
|
|
|
Re: How do I create a JUnit5 Test Suite in Eclipse? [message #1796880 is a reply to message #1796713] |
Sat, 20 October 2018 16:32 |
Reinhardt Christiansen Messages: 73 Registered: March 2010 |
Member |
|
|
Based on what you've said about the Oxygen update process, Ed, you've convinced me to upgrade to the newest stable release. Thanks!
UPDATE:
Well, that was disappointing. I installed the 2018-2019 Eclipse release without difficulty. However, I *still* can't create a JUnit5 Test Suite!
Initially, I just used the same workspace and let Eclipse convert it to the new format. Then I tried creating a test suite for the existing test cases I had. No dice: the only options I had were JUnit3 and JUnit4 test suites.
Then I tried creating an entirely new workspace for the new Eclipse install, then created a trivial class and a trivial test case for it. When I tried to create a new test suite for this code, I was *still* limited to creating only JUnit3 and JUnit4 test cases.
There must be a trick I haven't stumbled on yet. Can someone kindly point me to instructions or a video demonstrating how to make a JUnit5 test SUITE in a recent version of Eclipse?
Failing that, even an example of a basic JUnit5 test suite that has been manually written would be fine; then I'll just imitate that.
Your assistance would be greatly appreciated.
[Updated on: Sun, 21 October 2018 01:47] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03845 seconds