我不確定如何使用AbstractTestNGCucumberTests不確定如何使用AbstractTestNGCucumberTests
我有一個項目成立,旨在使用TestNG的運行黃瓜測試套件來啓動Eclipse內澆道類推出亞軍。
我遵循了所有的文檔我能找到的所有步驟,但我無法 推出的方式亞軍,承認在 類TestNG的註釋,如@BeforeMethod
項目如果我在runner類中取消註釋@RunWith行,但是當我評論@RunWith時,它將作爲Junit測試運行良好,但它不會作爲TestNG項目啓動,並且仍然表現爲junit項目。
如果我選擇CukesRunner並單擊「Run-As」,則不會顯示運行類型,並且我只能選擇將其作爲Junit從歷史記錄運行。我找不到啓動Cukesrunner的方法,它調用AbstractTestNGCucumberTests類的TestNG行爲。
TestNG插件在這個系統上工作正常,當他們不包括黃瓜和AbstractTestNGCucumberTests類時,testNG使項目運行正常。
下面是該項目的關鍵組成部分:
的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);
}
}
遊戲。功能
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 |
下面是項目結構的屏幕截圖:
感謝您的答覆。我仍然感到困惑。 –
1)我不明白這樣一句話:「它仍然可以通過手動創建運行配置文件從cukes亞軍執行它(只是指定你的TestNG的運行配置類)」 - 你的意思是在Eclipse中創建運行配置?我沒有成功與可言,沒有對運行配置工作的選項.....他們都失敗,各種錯誤,請參閱下面 2項-3))使用Maven ...這將是命令行, 對 ?你能提供一個示例命令行嗎? –
3)使用黃瓜特徵跑步者:我已經有一個cukesrunner文件,如前所示。我如何在Eclipse中運行它?如果我沒有@Runwith啓動,那麼它就不再是一個Junit測試。如果我嘗試運行它,因爲Java應用程序失敗,說沒有主類。如果我嘗試將它作爲Java Applet運行,它會失敗並顯示錯誤。沒有運行的TestNG選項。所以我完全茫然以怎樣一個應該從Eclipse中啓動這個....我似乎缺少真正的基本的東西在這裏... –