2013-07-05 39 views
13

cucumber-jvm javadocs指出glue元素的用途是指定stepdefinitions和hooks的位置。但是,這似乎不適用於我。可以說,我在目錄a中有我的功能,而在目錄b中有我的步驟定義。然後,黃瓜選項註釋

@Cucumber.Options(
     features= "directory_a", 
      glue="directory_b" 
) 

將從directory_a加載我有文件,但是,它不會從directly_b載入我的步驟定義。但是,如果我使用

@Cucumber.Options(
     features= {"directory_a", "directory_b"} 
) 

那麼我的功能從directory_a被加載,我的步驟定義從directory_b也被拿起。這正是我想要的,但是,我不明白爲什麼前者不工作?我猜它與它有關,期待URI的格式不同(也許我需要預先安裝一個類路徑://或類似的東西),但我在文檔中找不到關於此的任何信息。

+2

@ Cucumber.Options現在已過時,使用[CucumberOptions(http://cukes.info/api/cucumber/jvm/javadoc/cucumber/api/CucumberOptions.html) – Geert

+0

我想紀念這個問題已經過時。 –

回答

15

我已經成功地使用類似:

@RunWith(Cucumber.class) 
@Cucumber.Options(
    //this code will only look into "features/" folder for features 
    features={"classpath:features/"}, 
    glue = { "com.mycompany.cucumber.stepdefinitions", "com.mycompany.cucumber.hooks" }, 
    format = { "com.mycompany.cucumber.formatter.RuntimeInfoCatcher", "json:target/cucumber.json" }, 
    tags = { "@working" } 
    ) 
public class CucumberStarterIT { 
} 

望着文檔在http://cukes.info/api/cucumber/jvm/javadoc/cucumber/api/junit/Cucumber.Options.html它指定的選項是String[]類型所以也許它不是預期工作「以及」如果你不給它一個單值列表。試試glue={"directory_b"},看看會發生什麼。

+1

從上面的例子或文檔中我們並不清楚,但glue僅僅需要包名。 –

3

我有這個問題太......,至今它似乎到是:

「特色」正在尋找一個文件系統路徑

features = "src/foo/bar" 

而「膠水」正在尋找包名

glue = "foo.bar" 

不知道他們爲什麼不同,但這似乎對我有用。

+0

爲什麼它們不同的答案是功能是從一個目錄加載的,例如一個資源目錄。無論文件系統在何處,Glue都會遞歸地從所提及的包*和*所有子包中加載實際編譯的類。 – iZian