TestEngine with ID 'junit-jupiter' failed to discover tests 报错处理

513 阅读1分钟

最近想用 Kotlin 简单写一些 Playwright 方法自动化测试,写完基础的 Junit5 测试代码后,

点击 demo 运行时出现,TestEngine with ID 'junit-jupiter' failed to discover tests 的错误问题。 百度了一圈后,发现都是和 Spring Boot 关联的回答,项目并没有使用 Spring Boot,故记录一番解决的办法。

image.png

开始以为自己是代码语法写错了,捣鼓了一圈后发现是正确的。后面翻了一下 stackoverflow 才发现,原来是缺少了 junit-jupiter-api 依赖,所以在 pom.xml 里加入对应依赖。

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>对应的 junit-jupiter-engine 依赖版本</version>
    <scope>test</scope>
</dependency>

安装一下依赖

image.png

再次点击 demo 前的绿色运行箭头即可正常运行啦。

image.png

原因猜测是使用新版本的 IDEA 创建 Maven 项目的时候依赖少了 junit-jupiter-api ,应该是属于一个创建时模板 BUG,抽空再反馈一下给 JetBrains 团队。

The End