Deepak_Mahalingam
Deepak_Mahalingam

Reputation: 454

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

I am trying to execute as a maven project, I have added the dependencies in pom file and in maven dependencies also I can find the cucumber-junit jars. But still I cannot import the appropriate jar. Getting " The import cucumber.api.junit cannot be resolved ". Please find the attached screenshot

Dependency added in maven is

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

enter image description here

Folder structure of TestRunner Class

enter image description here

Upvotes: 1

Views: 16195

Answers (3)

sathish
sathish

Reputation: 289

  • Hover over in Runner class import io.cucumber.junit.Cucumber;
  • Click on "Organize imports" Suggestion.
  • This should remove the failure underline.

Upvotes: 0

Rashid Saleem
Rashid Saleem

Reputation: 13

You need these imports:

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

Upvotes: -1

Mehdi
Mehdi

Reputation: 3763

You have two options

1- change your folder structure:

src
  |
  test
     |
     your-package
                |
                YourClass

2- You can remove the scope test from the dependency as follows:

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

Upvotes: 12

Related Questions