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.
I'm running netbeans 10 as well, in xubuntu if that helps. I have no idea what is going on, so I had to revert to junit4. EDIT: To be perfectly clear, ant needs junit.jar which is nowhere to be found in the default netbeans 10 installation. Until someone brings a better solution, revert to junit4:
1) in your test libraries, right click and import the junit 4.1.2 ones.
2) remove the junit 5.3 ones.
3) scrap all the imports in your test file and use the junit4 ones. ie your imports will look like:
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import org.junit.*;
/*import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;*/
4) scrap the beforeAll and other test tags. Only leave the @Test one.
5) save all, close and re-open the project. It will complain that the hamcrest libraries for junit4 are not imported. Allow netbeans to fix it for you.
With that done, I was able to test successful and failing tests. I guess when you generate the junit tests with the template generator, it will generate the junit5 ones, so, a bit annoying. But you'll have tests!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With