-3

Installed IntelliJ in my new laptop Using JDK C:\Program Files\Java\jdk1.8.0_191

But Junit Test file giving error as Cannot resolve symbol Junit Cannot resolve symbol cucumber

Junit

Gayathri
  • 25
  • 2
  • 9
  • 1.2.5 info.cukes cucumber-java ${cucumber.version} info.cukes cucumber-junit ${cucumber.version} test junit junit 4.12 test – Gayathri Nov 08 '18 at 16:55
  • 1
    No images of code plz, copy paste it as text (into the question, not the comments) – Absent Nov 08 '18 at 16:55

4 Answers4

1

Assume the following simple structure

pom.xml
src/test/java/TestRunner.java

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.suboptimal</groupId>
    <artifactId>cuke-test.so</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <cucumber.version>1.2.5</cucumber.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

TestRunner.java

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        // add missing options here
        snippets = SnippetType.CAMELCASE
)
public class TestRunner {

}

Even the CucumberOptions is not filled completely you can run already the test.

$ mvn clean test

which produces following output

Running TestRunner
No features found at [classpath:]

Import this simple example in IntelliJ. If all other settings are correct you should be able to run it inside IntelliJ.

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • I copied POM XML as above but still having same issue , mvn is not recognised 'mvn' is not recognized as an internal or external command , Cannot resolve junit , java & cucumber – Gayathri Nov 09 '18 at 16:56
  • @Gayathri If you don't have Maven installed as external command, then create the above two files (in an empty directory of your choice) in the mentioned structure and import that directory as new project in IntelliJ to check if this is working. – SubOptimal Nov 12 '18 at 08:00
  • 1
    Thanks , I cloned it again as new prohject now , issue resolved I can execute Runner .java file.. – Gayathri Nov 13 '18 at 16:17
0

There are many reasons why this could be (you don't provide enough information).

But first, did you install the package? It is not contained in the standard jdk.

You can download and install cucumber via maven:

Visit https://maven.apache.org/ and https://docs.cucumber.io/installation/java/ for more Information.

Evoxx
  • 51
  • 5
  • Sorry I cannot Copy full POM XML org.apache.maven.plugins maven-compiler-plugin 3.3 1.8 1.8 UTF-8 – Gayathri Nov 08 '18 at 17:06
  • Added maven compiler should this work ? the same project works fine in Ecllipse – Gayathri Nov 08 '18 at 17:06
  • You have to install the cucumber package, if you are using maven just put the provided dependency into your pom.xml and reimport. – Evoxx Nov 08 '18 at 17:14
0

I also faced this issue in eclipse and it gets resolved on adding java compiler source and target configurations under tag in POM.xml

The sample POM.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hellocucumber</groupId>
    <artifactId>hellocucumber</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <cucumber.version>4.2.6</cucumber.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </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>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
PrateekSethi
  • 56
  • 1
  • 8
0

I have also faced this issue that intelliJ is unable to resolve below dependencies:

import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;

import org.junit.runner.RunWith;

And there is nothing wrong with the pom.xml file the same project is working fine on ecllipse IDE while when I switched to IntelliJ, it was not able to resolve dependency. Looking on the internet I have found this link and added an extra dependency of "junit-vintage-engine" Please refer this image Please vote up if this helps.

Abhishek
  • 11
  • 3