Pix81
Pix81

Reputation: 675

Setting up cucumber in intellij

I'm spinning my wheels trying to run tests in intellij. I'm using the basic framework of a cucumber skeleton project as such.

cucumber java

I have also updated my POM file as such:

    <?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>MaritProject</groupId>
    <artifactId>MaritProject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <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>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>

     </dependencies>
    </project>

Environment: I am on jdk 1.8 and the JDK has been selected in settings. I've also gone to settings, plug ins and installed the Cucumber for Java plug in. I'm on windows 10.

Requirement: I want to run a basic test of the feature file, which without having anything yet in my runner class, should tell me that zero tests are working and give me the basic output of a step definition file to cut and paste and start fleshing out details in. Then, I want to write and execute the runner file.

Problem: But when I run this feature file, either nothing happens or when I fill out some of the edit configuration, I get "Error running: 'Unnamed: No module defined'. I am following some video tutorials where the run output window looks much different than what I had, so I upgraded my IntellJ to the latest version, 2017.3.5

I have checked the markings on my directory and it looks like Java is correctly marked as Sources under main, java is marked as test Sources under src/test and resources are marked as resources under main and resources root under test. This probably should be all I need, as the video said to do even less than this. When I run mvn clean test in the directory of my project, I get BUILD SUCCESS back.

But, since I upgraded IntelliJ in attempt to correct a different issue, now I cannot run any feature or class file. It wants me to edit my configurations first. These configurations include a main class, glue, feature or folder path, VM options, program arguments, working directory, environment variables and classpath of module. This window was not there previously when I tried to run. I don't know what to put in any of these input boxes and google results have so far been unhelpful. How do I tell what my main class is or what the glue is? Glue looks like a required field, but I don't know what path corresponds to the glue. I can guess that my working directory is where the files are stored. I have my java and maven home environment variables saved on my machine, but do I also need them in intellij?

Upvotes: 2

Views: 4309

Answers (2)

Chai
Chai

Reputation: 2016

I have had some troubles getting this stuff to work. For this configuration works:

<properties>
    <java.version>1.8</java.version>
    <junit.version>4.12</junit.version>
    <cucumber.version>1.2.5</cucumber.version>
    <maven.compiler.version>3.3</maven.compiler.version>
</properties>
<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>

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

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Note that I have the versions specified a inside , they could also be provided inline.

Other than that you have to specify glue. This is the directory where your stepDefinition files are. Your glue and features and so on can be specified in a testrunnerclass or something like that. However note that this class HAS TO HAVE "Test" in the name. Something like TestRunner or CukesRunTest will do. RunnerClass will not be recognized.

Upvotes: 1

Marit
Marit

Reputation: 3026

Please remove

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

as you have two versions of cucumber currently in your pom.xml

Upvotes: 0

Related Questions