Netbeans中的JUnit 5测试

ctehm74n  于 2022-11-10  发布在  其他
关注(0)|答案(2)|浏览(140)

我在使用JUnit 5.52时遇到了问题,当我添加测试类并尝试运行它时,我得到了下一条消息:
The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's own classpath BUILD FAILED (total time: 0 seconds)
我运行的是Apache NetBeans IDE 11.3,我通过删除JUnit 5并使用JUnit 4.12解决了这个问题,但由于大学的要求,我可能会使用5.52。
有什么想法如何解决它,仍然使用JUnit 5.52或任何JUnit 5库?
先谢谢你。

ebdffaop

ebdffaop1#

您可以在https://github.com/junit-team/junit5-samples/tree/main/junit5-jupiter-starter-maven中找到有关如何在Netbeans中运行Junit 5的示例代码
您必须在POM中执行两项操作:

  • 包括Junit 5库
  • 在构建版本中包含足够新的maven-surefire-plugin版本

这是我测试过的一种配置,它可以正常工作:

<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>
zlwx9yxi

zlwx9yxi2#

似乎没有答案,降级到Junit4.12是唯一的解决方案。你也可以尝试手动重新安装jar库(我也试过)。

相关问题