2017-04-21 118 views
-1

我有問題與黃瓜運行testrunner。我需要有人幫我檢查@CucumberOptions。謝謝運行與黃瓜testrunner

package stepDefinition; 

import org.junit.runner.RunWith; 
import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 

@RunWith (Cucumber.class) 
@CucumberOptions (features = "Feature" 
        ,glue={"stepDefinition"}) 

public class testRunner { 

} 
+0

添加問題,什麼是項目結構?對於需要添加功能文件的目錄路徑的功能,如src \ test .... \ feature \。對於膠水添加包類路徑cucumber.test.steps – Grasshopper

回答

0

@RunWith(Cucumber.class)是用於JUnit集成。 如果你想用TestNG使用Cucumber,你必須用AbstractTestNGCucumberTests擴展你的課程。

你應該看看https://github.com/lionhearth/cucumber-testng這是一個完美的例子。

+0

謝謝juherr,我期待運行junit而不是testng。感謝您的補充信息。 – Tessy

0

這是我的測試。我將src中的定義/特徵文件作爲包裝。此外,我下載了黃瓜插件,但我無法看到顯示在我的功能中的顏色。如何引用特徵和步驟定義@cucumberoptions。

package stepDefinition; 

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


public class aptitudeTest { 

    @Given ("^I have successfully ([^\"]*)$") 
    public void I_have_(String str) 
    { 
     if (str.equals("registered")) 
     { 
      System.out.println("registered Automation"); 
     } 
     if (str.equals("unregistered")) 
     { 
      System.out.println("unregistered"); 
     } 
    } 

    @When ("^I enter my valid ([^\"]*)$") 
    public void I_enter_(String str) 
    { 
     if (str.equals("credentials")) 
     { 
      System.out.println("credentials Automation"); 
     } 
     if (str.equals("details")) 
     { 
      System.out.println("details"); 
     } 
    } 

     @Then ("^I should see the welcome([^\"]*)him $") 
     public void I_should_(String str) 
     { 
      if (str.equals("message")) 
      { 
       System.out.println("message Automation"); 
      } 
      if (str.equals("information")) 
      { 
       System.out.println("infomation"); 
      } 
     } 
    } 

這是我的特點

功能:登錄賬戶

@tester 場景:我看到消息時,我在

成功登錄鑑於我已經成功註冊 當我輸入了我的有效憑證 然後我應該看到歡迎訊息

鑑於我已成功取消註冊 當我輸入我的有效詳細信息 然後我應該看到歡迎消息

+0

我已解決上述問題。我發現我在依賴項中缺少黃瓜核心。另外,cucumber-core,cucumber-java,cucumber-junit都必須具有相同的版本。在另一篇文章的某處發現了這一點 – Tessy