Category Archives: cucumber

First Cucumber+java+maven project.

Prerequisite: following should be installed:
  • Java
  • Eclipse
  • Maven
  • maven-eclipse-plugin
  • Cucumber-eclipse-plugin

Step 1) Lets create a new project in eclipse by following steps:

Click on new –> Other –> Maven –> Maven Project — > Next

Step 2) Now click on Simple project and keep the default workspace location.

Step 3) Provide details as Artifact id, Group id, name and description. and click on Finish.

Step 4) This should create a basic maven project. 

Create packages as shown in the below snapshot and create new files in the project.

Feature file:

Feature:  Adding numbers with a Calculator
  In order to not learn math
  As someone who is bad at math
  I want to be able to add numbers using a Calculator
  Scenario:  Add two positive numbers
    Given I have a Calculator
    When I add 1 and 1
    Then the sum should be 2
  Scenario:  Add a positive and negative number
    Given I have a Calculator
    When I add 1 and -1
    Then the sum should be 0
  Scenario:  Add two negative numbers
    Given I have a Calculator
    When I add -1 and -1
    Then the sum should be -2

features = "src/test/resources/featurefile/caclculator.feature",
glue = {"com.steps"},
plugin = {"pretty", "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},

This class responsible for reading the features file 
Feature -- link of feature file
Glue Tag -- This holds the package containing steps
Plugin -- any report plugin you want to add.
Tags -- if you want to test specific tags methods like @functional @regression

package com.feature;

import org.junit.AfterClass;
import org.junit.runner.RunWith;

import com.cucumber.listener.Reporter;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(value = Cucumber.class)
(features = "src/test/resources/featurefile/caclculator.feature",
glue = {"com.steps"},
plugin = {"pretty", "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
public class Runnner {

    public static void writeExtentReport() {
        Reporter.setSystemInfo("Machine", "Windows 7:-" + "64 Bit");
        Reporter.setSystemInfo("Maven", "3.5.2");
        Reporter.setSystemInfo("Java Version", "1.8.0_151");
} :

package com.steps;

import static org.junit.Assert.assertEquals;

import com.feature.Calculator;


public class CalculatorSteps {

 private Calculator calculator;

 private int actualSum;
        //  ^ - denotes start of string in feature file given statement
 //  $ - denotes end of string in feature file given statement

 @Given("^I have a Calculator$")
 public void intializeCalculator() {
  this.calculator = new Calculator();
        //  ^ - denotes start of string in feature file when statement
 //  $ - denotes end of string in feature file when statement
        //  (-?\d)  denotes the parameter in number format

 @When("^I add (-?\d) and (-?\d)$")
 public void whenIAddTwoNumbers(int firstNumber, int secondNumber) {
  this.actualSum = this.calculator.add(firstNumber, secondNumber);

 @Then("^the sum should be (-?\d)$")
 public void thenTheSumShouldBe(int expectedSum) {
  assertEquals("The expected sum does not equal the actual sum", expectedSum, this.actualSum);

This class is our main class which we need to test using our feature file.This contains our logical code generally.

package com.feature;

public class Calculator {

 public int add(int firstNumber, int secondNumber) {
  return firstNumber + secondNumber;
Pom.xml :
<project xmlns="" xmlns:xsi=""
 <description> </description>
  <!-- Cucummber dependencies -->
         <!-- -->
        <!-- -->


As  you addded all these class and files now time to run the application

open class Runner and rightclick ->run as –>Junit test

You will see this on screen with all passing test cases.

Flow diagram of cucumber test.

73 total views, 1 views today

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description

Problem :

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
at cucumber.runtime.junit.FeatureRunner.getDescription(
at cucumber.api.junit.Cucumber.describeChild(
at cucumber.api.junit.Cucumber.describeChild(
at org.junit.runners.ParentRunner.getDescription(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Solution :

change you Junit version to latest i.e 4.12


88 total views, 1 views today

Install cucumber plugin in eclipse

If you are trying to install Cucumber Eclipse Plugin from eclipse market place then it might not work for you as it is not the main cucumber plugin for running the test as BDD. Even this is not a mandatory plugin but it is quite handy ,and your feauture file look like plain text.

Install Cucumber Eclipse Plugin
It is easy to install Cucumber Eclipse Plugin, as it comes as a plugin for Eclipse IDE. 

Steps to follow:

1) Launch the Eclipse IDE and from Help menu, click “Install New Software”.

2) You will see a dialog window, click “Add” button.

3) Type name as you wish, let’s assume “Cucumber plugin” and location “”. Click OK.

4) You come back to the previous window but this time you must see Cucumber Eclipse Plugin option in the available software list. Just Check the box and press “Next” button.

5) select and check Cucumber Eclipse Plugin from the list and click Next.

6) Click “I accept the terms of the license agreement” then click Finish.

7) Let it install, it will take few seconds to complete.

few more next and ok and installation part is done for cucumber plugin.

78 total views, no views today