Toothless
Toothless

Reputation: 369

Getting "Class<Cucumber> cannot be resolved to a type" for Cucumber.class while setting up JUnit

I'm using Cucumber 1.2.2 jar and getting error "Class cannot be resolved to a type" for the below code. Could someone suggest the solution.

Eclipse Code

Upvotes: 1

Views: 17441

Answers (4)

PRITEN PATEL
PRITEN PATEL

Reputation: 41

I was facing the same issue. I just made the "C" from the cucumber.class in lower case, and made it to Upper case again. When I made it in Uppercase it prompted me to do an import. And Finally I did the import and the issue was resolved. Here is what I imported.

import io.cucumber.junit.Cucumber;

I am using newer version of the Cucumber dependencies. I had tried all the solutions mentioned on stackoverflow, like removing the scope, downgrading the dependancy to match lower version of java installed on machine etc etc. Nothing worked. Only the solution which I provided worked.

Upvotes: 1

sweta kumari
sweta kumari

Reputation: 71

I Remove the scope for cucumber-junit dependency in pom.xml file and the error "the import cucumber.api.junit cannot be resolved" will be resolved.

Upvotes: 2

Testing Passion
Testing Passion

Reputation: 35

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
//The import cucumber.api.junit cannot be resolved
import cucumber.api.junit.Cucumber;
////Receiving an error message as Class<Cucumber> cannot be resolved to a type
@RunWith(Cucumber.class)

@CucumberOptions(
        features = "C:\\Users\\achelimi\\eclipse-workspace\\FirstAppl\\src\\main\\java\\feature\\login.feature", 
        glue = {"stepDefinition" }, 
        plugin = { "pretty", "html:test-outout", "json:json_output/cucumber.json",
                "junit:junit_xml/cucumber.xml" }, 
        monochrome = true, 
        strict = true, 
        dryRun = false)
public class TestRunner {

}

//Added below Dependencies for POM.xml

    <dependencies>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>1.2.5</version>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>4.2.0</version>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm</artifactId>
                <version>1.2.5</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>net.sourceforge.cobertura</groupId>
                <artifactId>cobertura</artifactId>
                <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.5</version>
            </dependency>
            <dependency>
                <groupId>net.masterthought</groupId>
                <artifactId>cucumber-reporting</artifactId>
                <version>1.0.0</version>
            </dependency>
//Added below Dependencies for POM.xml
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin</artifactId>
                <version>2.12.2</version>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>2.0.2-beta</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
//Added below Dependencies for POM.xml
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.0.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/info.cukes/gherkin-jvm-deps -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin-jvm-deps</artifactId>
                <version>1.0.2</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-html</artifactId>
                <version>0.2.3</version>
            </dependency>
   //Added below Dependencies for POM.xml

 //Added below Dependencies for POM.xml
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.6</version>
            <scope>system</scope>
            <systemPath>C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar</systemPath>
        </dependency>
    </dependencies>

Upvotes: 0

Grasshopper
Grasshopper

Reputation: 9058

You should have this import - import cucumber.api.junit.Cucumber;.

These options should be displayed by Eclipse on hovering over the error.

Upvotes: 5

Related Questions