首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@RunWith(Cucumber.class)错误。无法解析导入% cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)错误。无法解析导入% cucumber.api.junit.Cucumber;
EN

Stack Overflow用户
提问于 2018-08-13 00:49:37
回答 2查看 8.4K关注 0票数 1

我在所有的cucumber runner文件上都有这个问题。在pom.xml中使用以下依赖项。任何帮助都将不胜感激。

我尝试了清理并强制更新项目,并重新启动了集成开发环境,删除了.M2中的存储库文件夹,然后清理并强制更新项目,但它仍然不起作用。

代码语言:javascript
复制
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>

<!-- Extent Reports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.26-incubating</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>2.0.4</version>
</dependency>
EN

回答 2

Stack Overflow用户

发布于 2018-08-13 13:27:08

1.您添加了Cucumber-TestNG的依赖项,因此必须使用TestNG Runner语法调用Runner类。

带有TestNG的黄瓜的语法:

代码语言:javascript
复制
@CucumberOptions(features = "./src/main/java/cfeature", glue = {"stepd"}, monochrome = true,  plugin = { "pretty",  "html:Reports/cucumber-pretty" })

public class runnerDemo extends AbstractTestNGCucumberTests {   

}

它删除了Junit注解@RunWith并扩展了AbstractTestNGCucumberTests类。

2.如果你想用Junit运行cucumber测试,你需要用Cucumber-Junit替换Cucumber-testng依赖。而且您的语法将会工作得很好。

票数 0
EN

Stack Overflow用户

发布于 2022-02-19 12:07:10

cucumber-core cucumber-java cucumber-jUnit在pom.xml中使用1.2.6版本所有这些依赖项必须在同一版本中才能解决此问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51810880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档