3

I have troubles using JUnit 5.52 , when I add the test class and try running it I get the next message:


The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's own classpath BUILD FAILED (total time: 0 seconds)


I'm running Apache NetBeans IDE 11.3 and I solved it by deleting JUnit 5 and using JUnit 4.12 but I might use 5.52 because of university requirements.

Any idea how to solve it, still using JUnit 5.52 or any JUnit 5 library?

Thanks in advance.

skomisa
  • 16,436
  • 7
  • 61
  • 102
Rafael Mengui
  • 41
  • 1
  • 5
  • Does this answer your question? [NetBeans 10 JUnit Jar not found](https://stackoverflow.com/questions/54161715/netbeans-10-junit-jar-not-found) – skomisa May 20 '20 at 17:53
  • I don't think NetBeans 11.x supports the use of JUnit 5 for Ant projects. See [Junit 5, Apache Ant, and Apache NetBeans](https://blogs.apache.org/netbeans/entry/junit-5-apache-ant-and). As a workaround, can you create a Maven project that uses JUnit 5 instead? – skomisa May 20 '20 at 17:58

2 Answers2

0

You can find example code on how to run Junit 5 within Netbeans at https://github.com/junit-team/junit5-samples/tree/main/junit5-jupiter-starter-maven

You have to do 2 things in the POM:

  • include the Junit 5 libraries
  • include a version of the maven-surefire-plugin in the build that is recent enough

This is a configuration that I tested that works:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.stackoverflow.example</groupId>
    <artifactId>junit5</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.8.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                </configuration>
            </plugin>
        </plugins>
    </build>    
</project>
toongeorges
  • 1,844
  • 17
  • 14
-1

It seems there is no answer available, down grading to Junit 4.12 is the only solution. You could also try re-installing the jar library manually (which I tried also).

Rafael Mengui
  • 41
  • 1
  • 5
  • 2
    Asking a question and then answering it yourself and saying that there is no solution is not useful. The question is valuable, but if you do not know an answer, you should leave it open for others to answer. Others may have the same question and want to be helped instead of being misled that they cannot be helped. – toongeorges Jan 20 '22 at 19:57