7
votes

I created a RunTest class to run my test scenarios using Cucumber with JUnit. To run the tests before, I need to import into my project the RunWith class (@RunWith) and pass as parameter the Cucumber.class. Then, the RunWith parameter of the class recognizes more of the parameter that is passed to it, no. The eclipse displays the message:

Multiple markers at this line - Class can not be resolved to a type. - Cucumber can not be resolved to a type. - The annotation @RunWith must define the attribute value

I'm using Maven to organize my JARS files. Following is the code and error screens.

enter image description here enter image description here

My POM.XML

    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </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-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

    <!-- 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-jvm -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
        <type>pom</type>
    </dependency>

</dependencies>

My Libraries enter image description here

15
Have you tried to import Cucumber ? - dj_frunza
Indeed, try adding import cucumber.junit.Cucumber; . - Arnaud
Yes. I've tried but the eclipse displays the message: The import cucumber.junit can not be resolved. I think I'm missing some JAR file in my project. - Kakashi - Sensei
In your pom.xml you have the dependency info.cukes:cucumber-jvm:pom:1.2.5 which is not in the list of dependencies on any of your screenshots. What happen if you run mvn compile on command line? I created a small project with your pom.xml and RunTest.java and it compiles just ok. - SubOptimal

15 Answers

9
votes

I also faced the same issue in IntelliJ idea, When I check in the imported libraries it was like below screenshot.

screenshot

So I remove scope tag from my import in pom file.Then it worked.

Earlier

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

Fix

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

Now it is working fine

7
votes

Import the cucumber.api.junit.Cucumber class. It seems you are using Eclipse IDE, so you can import the classes using the Ctrl+Shift+o (alphabet 'o' not zero) shortcut.

(Ctrl+Shift+O is 'Organise Imports', and will add any missing imports, remove any unused ones, and order all of your imports). The command is also found under Source > Organise Imports.

1
votes

Just do Ctrl+Shift+T and type RunWith check if the jar is correctly imported into your work space after maven dependencies are resolved.

1
votes

I removed my POM.xml file from the dependency below:

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

And I added the dependency:

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>3.0.2</version>
        <scope>test</scope>
    </dependency>

Done that I was able to do import.

enter image description here

1
votes

Step 1: Mouse hovering on error shows, class cucumber cannot be resolved to a type. so, write the import statement manually and the error will be gone.

import cucumber.api.junit.Cucumber;

Step 2: Remove scope from pom.xml file for cucumber-JUnit dependency.

1
votes

For me the same issue was resolved by deleting .m2/repository, restart IDEA with dependencies as follows:

${cucumber.version} = 4.8.0

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

Hope, it works for you as well.

1
votes

I was also facing the same issue.I just removed scope part from the cucumber-junit dependency and it worked fine for me.

1
votes

I have removed the test tag and it worked.

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

I ran into the same problem. I am using a Maven project in Eclipse. My problem seemed to be the JRE version I was using. My Maven projects all had an old J2SE-1.5 I switched to 1.8 within Eclipse and the issue went away. Hope this helps!

0
votes

As mentioned above, adding the below dependency resolved my issue:

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>3.0.2</version>
        <scope>test</scope>
    </dependency>
0
votes

Downloaded all the latest jar maven dependencies from "mvnrepository". This worked for me.

0
votes

Please add this dependency and remove old one. it worked for me.

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>
0
votes

Even though you might have cucumber-junit in pom.xml

Confirm that under Maven Dependencies you must have cucumber-junit

enter image description here

I had 1.2.6 but it was not under Maven dependencies, Got this from one the comments in the answer.

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

I changed:

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.1.2</version>
        <scope>test</scope>
    </dependency>

To:

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>6.2.0</version>
    <scope>test</scope>
</dependency>

It Worked...

My Dependencies list:

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>6.2.0</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>
  
   <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>6.2.0</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13</version>
    <scope>test</scope>
</dependency>
-1
votes

I have faced the same issue. Tried multiple things but what helped me is this
import cucumber.api.junit.Cucumber;