使用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
5条答案
按热度按时间w6mmgewl1#
将依赖项添加到
pom.xml
:polkgigr2#
在不使用maven的情况下,Junit 5的依赖项是:
朱尼特-朱庇特-API
木星发动机
组合平台发动机
junit-platform-commons
junit-vintage-engine(可选)
它们可以被发现:https://junit.org/junit5/
dtcbnfnu3#
在我的情况下,我们正在使用gradle,不知何故,我无法解决它,我已经在eclipse中手动添加了jar,现在它正在工作。在Eclipse项目中→ build path → config build path -> libraries →添加所有与“jupiterEnginer5.5”相关的库。以下是“jupiterEnginer5.5”的所有jar文件:opentest4j-1.2.0.jar junit-platform-engine-1.7.0-M1.jar junit-platform-commons-1.7.0-M1.jar junit-jupiter-engine-5.7.0-M1.jar junit-jupiter-api-5.7.0-M1.jar apiguardian-api-1.1.0.jar
shyt4zoc4#
添加此修复我的问题
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
bfhwhh0e5#
有时候,它是由于重命名包,然后没有重构构建/运行配置而导致的