尝试运行 Serenity JBheave 时出现“java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector”

Tim*_*hua 5 java testing bdd jbehave maven

使用 Maven(通过命令行)创建了一个新的通用 Serenity BDD JBehave 框架。

将项目导入 Intelli J,但是当我尝试运行“AcceptanceTestSuite”时,我收到一条错误消息,指出“未找到测试”和以下错误Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector

我试过重新导入该项目,但这并不能解决问题。

这是完整的错误日志:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetPublicMethods(Class.java:2902)
    at java.lang.Class.getMethods(Class.java:1615)
    at org.jbehave.core.steps.AbstractStepsFactory.hasAnnotatedMethods(AbstractStepsFactory.java:70)
    at net.serenitybdd.jbehave.SerenityStepFactory.getCandidateClasses(SerenityStepFactory.java:61)
    at net.serenitybdd.jbehave.SerenityStepFactory.stepsTypes(SerenityStepFactory.java:48)
    at org.jbehave.core.steps.AbstractStepsFactory.createCandidateSteps(AbstractStepsFactory.java:34)
    at net.serenitybdd.jbehave.SerenityStepFactory.createCandidateSteps(SerenityStepFactory.java:42)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.buildCandidateSteps(SerenityReportingRunner.java:294)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.createCandidateStepsWith(SerenityReportingRunner.java:249)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.createCandidateStepsWithNoMonitor(SerenityReportingRunner.java:257)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getCandidateSteps(SerenityReportingRunner.java:240)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.buildDescriptionFromStories(SerenityReportingRunner.java:313)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getDescriptions(SerenityReportingRunner.java:84)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getDescription(SerenityReportingRunner.java:168)
    at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:78)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.DiscoverySelector
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 21 more
Run Code Online (Sandbox Code Playgroud)

VaL*_*VaL 9

将依赖添加到pom.xml

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-engine</artifactId>
    <version>1.2.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

  • 我正在使用 VS Code,但这并不能解决我的问题 (4认同)

An_*_*_Bk 5

不使用 Junit 5 的 Maven 依赖项是:

junit-jupiter-api

junit-木星引擎

junit-平台-引擎

junit-platform-commons

junit-vintage-engine(可选)

可以找到它们:https : //junit.org/junit5/