Unsure how to launch runner using AbstractTestNGCucumberTests

210 views
Skip to first unread message

Charles Radley

unread,
Aug 19, 2016, 12:37:40 PM8/19/16
to Cukes

I am Unsure how to launch the runner class within Eclipse using AbstractTestNGCucumberTests

I have a project set up, intended to use TestNG to run a Cucumber test suite.

I have followed all the steps in all the docs I can find, but I am unable to launch the runner in a manner which recognizes the testNG annotations in the class, such as @BeforeMethod

The project runs fine as a Junit test if I uncomment the @RunWith line in the runner class, but when I comment the @RunWith, then it does not launch as a TestNG project, and still behaves as a junit project.

If I select the CukesRunner an click "Run-As" there is no run type displayed, and I can only select to run it as Junit from the history record. I can find no way of launching the Cukesrunner such that it invokes the TestNG behavior of the AbstractTestNGCucumberTests class.

The TestNG plugin is working fine on this system, testNG enable projects run fine when they do not include the cucumber nor AbstractTestNGCucumberTests class.

Here are the key components of the project:

testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Cucumber-numbers-game" >
  <test name="Play_Games" >
    <classes>
      <class name="com.example.GameSteps" />  
    </classes>
  </test>
</suite>

pom.xml

<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.example</groupId>
  <artifactId>example</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

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

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

  <repositories>
    <repository>
      <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <dependencies>

      <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.4</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-junit</artifactId>
      <version>1.1.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>1.1.3</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

CukesRunner.java

package com.example;

import cucumber.api.junit.Cucumber;
// import org.junit.runner.RunWith;
import cucumber.api.testng.AbstractTestNGCucumberTests;

// @RunWith(Cucumber.class)
@Cucumber.Options(
        features={"src/test/resources"}
)
public class CukesRunner extends AbstractTestNGCucumberTests{}

GameSteps.java

package com.example;    
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.testng.annotations.*;
import static org.junit.Assert.assertEquals;

public class GameSteps {
    private Game _target;
    private String _actualResult;

    @BeforeMethod
    public void setUp() {
    System.out.println("@BeforeMethod: The annotated method will be run before each test method.");
    }

    @Test

    @Given("^I am officiating a \"([^\"]*)\" game$")
    public void I_am_officiating_a_game(String gameTypeName) {
        System.out.println("^I am officiating a \"([^\"]*)\" game$");
        GameType gameType = GameType.valueOf(gameTypeName);
        _target = GameFactory.createGame(gameType);
    }

    @When("^the number (\\d+) is played$")
    public void the_number_is_played(int playedNumber) {
        System.out.println("^the number (\\d+) is played$");
        _actualResult = _target.checkPlay(playedNumber);
    }

    @Then("^I should be told the correct answer is \"([^\"]*)\"$")
    public void I_should_be_told_the_correct_answer_is(String expectedResult) {
        System.out.println("^I should be told the correct answer is \"([^\"]*)\"$");
        assertEquals(expectedResult, _actualResult);
    }
}

Game.feature

Feature: Number Games
  So that plays can be validated
  As a number game umpire
  I want to enter a play and see the correct answer

  Scenario Outline: A game of FizzBuzz
    Given I am officiating a "FizzBuzz" game
    When the number <played> is played
    Then I should be told the correct answer is "<result>"

  Examples:
    | played | result   |
    | 1      | 1        |
    | 2      | 2        |
    | 3      | Fizz     |
    | 5      | Buzz     |
    | 6      | Fizz     |
    | 10     | Buzz     |
    | 15     | FizzBuzz |

  Scenario Outline: A game of Crash Bang Wallop
    Given I am officiating a "CrashBangWallop" game
    When the number <played> is played
    Then I should be told the correct answer is "<result>"

  Examples:
    | played | result          |
    | 1      | 1               |
    | 2      | 2               |
    | 3      | Crash           |
    | 5      | Bang            |
    | 7      | Wallop          |
    | 15     | CrashBang       |
    | 35     | BangWallop      |
    | 21     | CrashWallop     |
    | 105    | CrashBangWallop |

Here is a screenshot of the project structure:

Here is a screenshot of the project structure:

Reply all
Reply to author
Forward
0 new messages