簡體   English   中英

運行測試時出現黃瓜異常

[英]Cucumber exception when run the test

我有一個我認為很愚蠢的問題......我無法對黃瓜進行測試。

返回以下錯誤:

cucumber.runtime.CucumberException: 

Classes annotated with @RunWith(Cucumber.class) must not define any
Step Definition or Hook methods. Their sole purpose is to serve as
an entry point for JUnit. Step Definitions and Hooks should be defined
in their own classes. This allows them to be reused across features.
Offending class: class Teste.testecucumber

有人可以幫忙嗎?

謝謝 !!

@Runwith 在 Cucumber 項目的 TestRunner 類中聲明。 Cucumber 項目定義了 3 種類:

  1. 步驟定義類
  2. 要素類
  3. 跑步類

請找到上述類的以下示例:

1. 要素類

測試用例寫在這個類中

   Feature: Title of your feature
   I want to use this template for my feature file

   @tag1
   Scenario: Verify login to the system.
   Given I navigate to url
   And I enter username as "username"
   And I enter password as "password"
   When I click Login
   Then I should be logged into the system

2. Step 定義類

特征步驟在這個類中定義

    public class LoginPage(){

     @Given("I navigate to the url")
     public void navigate() {

        /* your code for the above 
        step comes here*/
      }

     }

3. 跑者班

runner 類由特征位置和步驟定義組成。 它是一個 Junit 類,不能包含黃瓜步驟定義注釋。 (這就是 runner 類不能是步驟定義類的原因)。 但是,您可以在此類中包含 BeforeClass、AfterClass(Junit 注釋)

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

 @RunWith(Cucumber.class)
 @CucumberOptions( 
 features = {"classpath:<location of your folder with feature classes / package name>"},
 glue = {"<package name>" },
 tags = { "<the tags that has to be executed>","can be comma separated multiple tags" }
 )



 public class testrunner {

   //@AfterClass
   public static void quitDriver() {
    driver.quit();
   }
}

希望這對你有幫助!

暫無
暫無

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

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