1
votes

Test Data :-

1)Java java version "1.8.0_121" Java(TM) SE Run-time Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

2)Eclipse Eclipse IDE for Java Developers Version: Neon.2 Release (4.6.2) Build id: 20161208-0600

3)OS Microsoft Windows 10 Home - 64-Bit

myFeature.feature

Feature: This is my dummy feature file

Scenario: This is my first dummy scenario
Given This is my first dummy given step
When This is my second dummy given step
Then This is my third dummy given step

steps.java

package com.cucumber.mavenCucumberPrototype;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class steps
{
@Given("^This is my first dummy given step$")
public void This_is_my_first_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first given step");
}
@When("^This is my second dummy given step$")
public void This_is_my_second_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first when step");
}
@Then("^This is my third dummy given step$")
public void This_is_my_third_dummy_given_step() throws Throwable
{
    System.out.println("Executed the first then step");
}
}

RunnerTest.java

package com.cucumber.mavenCucumberPrototype;

import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "classpath:features"
            )

public class RunnerTest
{

}

POM.XML

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.cucumber</groupId>
<artifactId>mavenCucumberPrototype</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mavenCucumberPrototype</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

    </pluginManagement>
</build>

Stack Trace :-

java.lang.TypeNotPresentException: Type cucumber.junit.Cucumber not present
at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:84)
at com.sun.proxy.$Proxy2.value(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: cucumber.junit.Cucumber
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:349)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521)
at java.lang.Class.annotationData(Class.java:3510)
at java.lang.Class.getAnnotation(Class.java:3415)
at org.junit.internal.builders.IgnoredBuilder.runnerForClass(IgnoredBuilder.java:10)
... 11 more

COmmand Line Output :-

C:\Users\Pragati Chaturvedi\workspace\mavenCucumberPrototype>mvn clean 
install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mavenCucumberPrototype 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ 
mavenCucumberPrototype ---
[INFO] Deleting C:\Users\Pragati 
Chaturvedi\workspace\mavenCucumberPrototype\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 
mavenCucumberPrototype ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Pragati 
Chaturvedi\workspace\mavenCucumberPrototype\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ 
mavenCucumberPrototype ---
[INFO] Nothing to compile - all classes are up to date
 [INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenCucumberPrototype ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\Users\Pragati 
   Chaturvedi\workspace\mavenCucumberPrototype\src\test\resources
   [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ 
   mavenCucumberPrototype ---
  [INFO] Changes detected - recompiling the module!
  [INFO] Compiling 2 source files to C:\Users\Pragati 
  Chaturvedi\workspace\mavenCucumberPrototype\target\test-classes
  [INFO]
  [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ 
  mavenCucumberPrototype ---
  [INFO] Surefire report directory: C:\Users\Pragati 
  Chaturvedi\workspace\mavenCucumberPrototype\target\surefire-reports

   -------------------------------------------------------
  T E S T S
-------------------------------------------------------
Running com.cucumber.mavenCucumberPrototype.RunnerTest
No features found at [classpath:features]

 0 Scenarios
 0 Steps
 0m0.000s
 Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.331 sec
 Results :
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
 [INFO]
 [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mavenCucumberPrototype 
  ---
 [WARNING] JAR will be empty - no content was marked for inclusion!
 [INFO] Building jar: C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\target\mavenCucumberPrototype-
 0.0.1-SNAPSHOT.jar
 [INFO]
 [INFO] --- maven-install-plugin:2.4:install (default-install) @ 
 mavenCucumberPrototype ---
 [INFO] Installing C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\target\mavenCucumberPrototype-
 0.0.1-SNAPSHOT.jar to C:\Users\Pragati 
 Chaturvedi\.m2\repository\com\cucumber\mavenCucumberPrototype\0.0.1-
 SNAPSHOT\mavenCucumberPrototype-0.0.1-SNAPSHOT.jar
 [INFO] Installing C:\Users\Pragati 
 Chaturvedi\workspace\mavenCucumberPrototype\pom.xml to C:\Users\Pragati 
 Chaturvedi\.m2\repository\com\cucumber\mavenCucumberPrototype\0.0.1-
  SNAPSHOT\mavenCucumberPrototype-0.0.1-SNAPSHOT.pom
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 3.794 s
    [INFO] Finished at: 2017-04-12T01:36:58-04:00
   [INFO] Final Memory: 17M/194M
     [INFO] ------------------------------------------------------------------------

http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException`C:\Use rs\PragatiChaturvedi\workspace\mavenCucumberPrototype\src\test\java\com\cu cumber\mavenCucumberPrototype>javac RunnerTest.java RunnerTest.java:5: error: package cucumber.api does not exist import cucumber.api.CucumberOptions; ^ RunnerTest.java:6: error: package cucumber.api.junit does not exist import cucumber.api.junit.Cucumber; ^ RunnerTest.java:9: error: cannot find symbol @CucumberOptions( ^ symbol: class CucumberOptions RunnerTest.java:8: error: cannot find symbol @RunWith(Cucumber.class) ^ symbol: class Cucumber 4 errors C:\Users\PragatiChaturvedi\workspace\mavenCucumberPrototype\src\test\java\com\ ucumber\mavenCucumberPrototype>javac steps.java steps.java:3: error: package cucumber.api.java.en does not exist import cucumber.api.java.en.Given; ^ steps.java:4: error: package cucumber.api.java.en does not exist import cucumber.api.java.en.Then; ^ steps.java:5: error: package cucumber.api.java.en does not exist import cucumber.api.java.en.When; ^ steps.java:9: error: cannot find symbol @Given("^This is my first dummy given step$") ^ symbol: class Given location: class steps steps.java:14: error: cannot find symbol @When("^This is my second dummy given step$") ^ symbol: class When location: class steps steps.java:19: error: cannot find symbol @Then("^This is my third dummy given step$") ^ symbol: class Then location: class steps 6 errors

2
How did you run the test? If it was from your IDE, please try from command line to see if the error exists stilldjames
please dont use the comment section to these details. You can always edit your question. I believe you are not using 'maven clean verify' to run the test.djames
@djames: Thanks for your response. I have updated command line output in the question. However, I am getting error on running maven clean verify' command as mention abovePragati Chaturvedi
you should learn about maven. In this case run 'mvn clean verify' from C:\Users\Pragati Chaturvedi\workspace\mavenCucumberPrototype, or the folder in which your pom file resides.djames

2 Answers

2
votes

I tried with this in my POM.XML and it's works

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

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.3</version>
            <scope>test</scope>
        </dependency>

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

    </dependencies>

</project>
1
votes

This is a maven project and javac is not the way to compile/build the project.

Correct me if I am wrong, but I would assume that you are not aware of maven. These are few tutorials on maven.

Try running mvn clean install from C:\Users\PragatiChaturvedi\workspace\mavenCucumberPrototype and see if tests are getting executed.