测试运行程序文件-悬停错误不会提示用户导入api

问题描述

我在Eclipse中创建了一个New Maven项目,然后创建了一个新的“功能文件”,“步骤定义”和“ Testrunner”。但是,当我将鼠标悬停在Test Runner类的不同注释上时,会看到很多错误消息。参见下文{1至5}

我在Internet上进行了大量研究,并在pom.xml文件添加了一些依赖项,但似乎没有任何作用。

我当前在pom.xml文件中具有以下依赖项

<dependency>

  <groupId>junit</groupId>

  <artifactId>junit</artifactId>

  <version>3.8.1</version>

  <scope>test</scope>

</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<groupId>io.cucumber</groupId>

<artifactId>cucumber-java</artifactId>

<version>6.8.2</version>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<groupId>io.cucumber</groupId>

<artifactId>cucumber-junit</artifactId>

<version>6.8.2</version>

<scope>test</scope>
  1. 当我将鼠标悬停在黄瓜上时,我收到以下消息
  • 黄瓜不能解析为变量
  1. 当我将鼠标悬停在@RunWith上时,我得到以下信息
  • RunWith无法解析为类型
  1. 当我将鼠标悬停在@CucumberOptions上时,我得到以下内容
  • CucumberOptions无法解析为类型
  1. 当我将鼠标悬停在importcuming.api.junit.Cucumber上时;我得到以下内容
  • 无法解析导入的cumul.api.junit
  1. 当我将鼠标悬停在importcuming.api.CucumberOptions;上时。我得到以下内容
  • 无法解析导入的cumul.api.CucumberOptions

似乎它必须对jre文件进行处理。这是我根据在stackoverflow中可以找到的响应尝试过的解决方案 A]互联网上的一些解决方案建议我将以下依赖项添加到pom.xml文件中,但不能解决问题

<groupId>info.cukes</groupId>

<artifactId>cucumber-junit</artifactId>

<version>1.2.6</version>

<type>pom</type>

<scope>test</scope>

注意:-即使将它们添加到pom.xml文件中,我在Maven依赖项列表下也看不到它。

B]添加了进口黄瓜.junit.Cucumber;

但即使这样也没有帮助

C]注释掉@RunWith(Cucumber,class)并将以下依赖项添加到pom.xml文件

<groupId>info.cukes</groupId>

<artifactId>cucumber-junit</artifactId>

<version>1.2.5</version>

<type>pom</type>

<scope>test</scope>

注意:-针对“ import banana.api.CucumberOptions;”的错误消息消失了,但是针对“ importcuming.api.junit.Cucumber;”的错误消息仍然显示

关于, 罗希特(Rohit)

解决方法

我能够解决此问题。

解决方案:-验证Eclipse环境是否正在使用JUNIT4

步骤:

  1. 单击项目->属性-> Java构建路径->库

  2. 然后单击“添加库”

  3. 在“选择要添加的库类型”窗口上,选择“ JUNIT”并单击“下一步”,然后单击“完成”

    JUNIT出现在Java Build Path窗口中

  4. 单击“应用并关闭”。