簡體   English   中英

黃瓜測試未運行

[英]Cucumber test not running

我正在研究我的第一個特征文件/ selenium項目。

我創建了一個功能文件和跑步者類。

 package cucumberpkg2; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions (features="Features") public class Runner { } 
我有功能文件test.feature

 Feature: Login screen Scenario Outline: Successful login Given User is on Login page When User enters valid UserName and Password And Clicks the login button Then User landed on the home page 

但每當我嘗試將TestRunner類作為JUnit測試運行時,我都會收到錯誤:

在所選項目中找不到測試類。

以下是您的問題的解決方案:

  1. 根據Cucumber的當前文檔,您可能需要在test.feature文件中將關鍵字Scenario Outline更改為Scenario
  2. 雖然你提到了TestRunner類,但是你的代碼講的是Runner類被實現為public class Runner ,但是要確保你作為JUnit test執行哪個類文件。
  3. 對於以前的版本,您可能需要將@CucumberOptions更改為@Cucumber.Options (最新版本適用於@CucumberOptions
  4. 將以下兩部分放在一行中@Cucumber.Options (features="Features")
  5. 正如您所提到的, @Cucumber.Options(features="Features")確保您的要素文件放在項目目錄中的Features子目錄中。
  6. 因此,您將在Features子目錄中使用以下代碼獲得test.feature文件:

     Feature: Login screen Scenario: Successful login Given User is on Login page When User enters valid UserName and Password And Clicks the login button Then User landed on the home page 
  7. 你的Runner類看起來像:

     import org.junit.runner.RunWith; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions(features="Features") public class Runner { } 
  8. 最后,當您將Runner類作為JUnit測試執行時,您將在控制台上看到以下消息:

     You can implement missing steps with the snippets below: @Given("^User is on Login page$") public void User_is_on_Login_page() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @When("^User enters valid UserName and Password$") public void User_enters_valid_UserName_and_Password() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @When("^Clicks the login button$") public void Clicks_the_login_button() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } @Then("^User landed on the home page$") public void User_landed_on_the_home_page() throws Throwable { // Express the Regexp above with the code you wish you had throw new PendingException(); } 
  9. 通過為Cucumber實施glue選項,可以輕松地注意這些警告。

如果這回答你的問題,請告訴我。

您需要提供功能文件的完整路徑,如下所述。

@RunWith(Cucumber.class)
@CucumberOptions(
                features = {"src/test/resources/com/gaurang/steps/demo.feature",
                            "src/test/resources/com/gaurang/steps/demo1.feature"
                            }
                )
public class RunAllTest {

}

或者,如果您有太多的功能文件,最好的方法是為功能文件提供標簽,然后使用這些標簽運行,如下所述。

@userRegistrations
Feature: User Registration

RunAllTest.java

@RunWith(Cucumber.class)
@CucumberOptions(tags={"@userRegistrations"})
public class RunAllTest {
}

您可以使用多個標簽

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM