Cucumber 无法解析为类型。 @RunWith(Cucumber.class)

Cucumber cannot be resolved to a type. @RunWith(Cucumber.class)

我正在尝试作为 maven 项目执行,我在 pom 文件和 maven 依赖项中添加了依赖项,我也可以找到 cucumber-junit jar。但我仍然无法导入合适的罐子。获得 " The import cucumber.api.junit cannot be resolved "。请找到随附的屏幕截图

maven中添加的依赖是

<dependency>
     <groupId>info.cukes</groupId>
     <artifactId>cucumber-junit</artifactId>
     <version>1.2.5</version>
     <scope>test</scope>
 </dependency>

TestRunner 的文件夹结构Class

您需要这些导入:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

你有两个选择

1- 更改您的文件夹结构:

src
  |
  test
     |
     your-package
                |
                YourClass

2- 您可以按如下方式从依赖项中删除范围测试:

<dependency>
     <groupId>info.cukes</groupId>
     <artifactId>cucumber-junit</artifactId>
     <version>1.2.5</version>
 </dependency>