Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber cannot be resolved to a type

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

like image 574
Kakashi - Sensei Avatar asked Jul 03 '18 09:07

Kakashi - Sensei


2 Answers

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

like image 72
Sandunika Wijerathne Avatar answered Oct 20 '22 14:10

Sandunika Wijerathne


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.

like image 9
nikhil Ingole Avatar answered Oct 20 '22 14:10

nikhil Ingole