'JUnit 5 test in Netbeans

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.



Solution 1:[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).

Solution 2:[2]

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>

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 Rafael Mengui
Solution 2