日期:2024-03-07  浏览次数:91 次

groups/excludedGroups require TestNG, JUnit48+ or JUnit 5 on project test classpath解决方案

清空下Invalidate Caches缓存再添加依赖项就可以了。

这个错误信息表明在项目的测试类路径上缺少 TestNG、JUnit 4.8+ 或 JUnit 5 的相关依赖,而您的代码中使用了与测试相关的注解或功能,如 @Test(groups = ...), @Test(excludedGroups = ...), 等等。

为了解决这个问题,您需要在项目的测试类路径中添加相应的测试框架依赖,具体取决于您选择使用的测试框架(TestNG、JUnit 4.8+ 或 JUnit 5)。

如果您正在使用 Maven 作为项目构建工具,您可以在 Maven 的 pom.xml 文件中添加相应的依赖。以下是示例:

 

<!-- 添加 TestNG 依赖   亲测可以 -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.5.1</version> <!-- 或者您希望使用的 TestNG 版本 -->
    <scope>test</scope>
</dependency>

<!-- 或者添加 JUnit 4 依赖 -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version> <!-- 或者您希望使用的 JUnit 4 版本 -->
    <scope>test</scope>
</dependency>

<!-- 或者添加 JUnit 5 依赖 -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.8.1</version> <!-- 或者您希望使用的 JUnit 5 版本 -->
    <scope>test</scope>
</dependency>
 

请根据您选择的测试框架,在 pom.xml 文件中添加适当的依赖,并确保它们在测试运行时可用。