'NetBeans 10 JUnit Jar not found

I have a new installation of NetBeans 10. Trying to run some initial unit tests I just created, I get the following error:

The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's own classpath

I could probably hack the build script to include junit.jar, but I want to know: what's the right way to fix this?

Shouldn't NetBeans come with a version of JUnit already accessible? Should I configure my project differently? How do I add a path to the library?

How can I find the classpath for Ant (and what version/binary NetBeans is using)?

The project Test Libraries shows that JUnit 5.3.1 is present, I have three Jar files listed there: junit-jipiter-api, junit-jupiter-params, junit-jupiter-engine. But it seems to be not actually found.

The project is a standard Java Library (no main class). I didn't add any "extras" or mess with the default project setup that NetBeans uses. Just used the basic setup wizard thing.


Re. a reply from the NetBeans mailing list by Geertjan Wielenga, he pointed me at this thread and reply:

Yep...

We never got around to implementing JUnit 5 support for Ant based projects in NB 10.

John McDonnell

http://mail-archives.apache.org/mod_mbox/netbeans-users/201901.mbox/%3cCAAuDyk6WcgLaUDz0dp=4Arr7QGnwWcYey3VOeGojRRMRqVZrFA@mail.gmail.com%3e

So I think it's just not going to work. I'll try the suggested reversion to JUnit 4 below.



Solution 1:[1]

I had the same error but it was not a configuration issue, it was only a typo.

The main method of the class I was testing was written like this:

public static void main(String agrs) {
 ///
}

The only thing I had to do was to write it properly, like this:

public static void main(String[] args) {
 ///
}

Once I changed it, the problem was gone. I suppose this is not a global solution, but may help some.

Solution 2:[2]

I found a better solution to the accepted answer is to select JUnit 4 from Create/Update tests. Then you don't have to reconfigure your tests every time.

From Netbeans: https://netbeans.apache.org//kb/docs/java/junit-intro.html#_writing_junit_3_unit_tests

Solution 3:[3]

I faced the same problem. I removed the existing Junit 5 files and added the files here instead.

https://github.com/junit-team/junit4/wiki/Download-and-Install

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AlbertoLopez
Solution 2
Solution 3 ebubekiracar