2016-02-10 35 views
1

我有一個應用程序,我正在使用不同的技術進行試用。我有一套使用每種技術實現的接口,我使用彈簧配置文件來決定運行哪種技術。每種技術都有自己的Spring java配置,並註明了它們的活動配置文件。是否可以配置黃瓜運行不同的春季配置文件相同的測試?

我跑我的黃瓜測試確定哪種模式處於活動狀態,但是這迫使我我想測試一個不同的配置文件每次手動更改字符串,使其無法運行所有這些自動化測試。無論如何,在黃瓜提供一套配置文件,所以測試每個運行一次?

謝謝!

回答

1

你有兩種可能性

  1. 標準 - 用一些測試類跑黃瓜選手
  2. 編寫自定義黃瓜JUnit運行(或採取準備一個),支持多種配置。

在第一種情況下,它將如下所示。缺點是你必須爲每個運動員定義不同的報告,併爲每個配置使用幾乎相同的Cucumber運動員。

enter image description here

這裏的類怎麼能是這樣的:

CucumberRunner1.java

@RunWith(Cucumber.class) 
@CucumberOptions(glue = {"com.abc.def", "com.abc.common"}, 
     features = {"classpath:com/abc/def/", 
       "classpath:com/abc/common.feature"}, 
     format = {"json:target/cucumber/cucumber-report-1.json"}, 
     tags = {"[email protected]"}, 
     monochrome = true) 
public class CucumberRunner1 { 
} 

StepAndConfig1.java

@ContextConfiguration(locations = {"classpath:/com/abc/def/configuration1.xml"}) 
public class StepsAndConfig1 { 
    @Then("^some useful step$") 
    public void someStep(){ 
     int a = 0; 
    } 
} 

CucumberRunner2.java

@RunWith(Cucumber.class) 
@CucumberOptions(glue = {"com.abc.ghi", "com.abc.common"}, 
     features = {"classpath:com/abc/ghi/", 
       "classpath:com/abc/common.feature"}, 
     format = {"json:target/cucumber/cucumber-report-2.json"}, 
     tags = {"[email protected]"}, 
     monochrome = true) 
public class CucumberRunner2 { 
} 

OnlyConfig2.java

@ContextConfiguration(classes = JavaConfig2.class) 
public class OnlyConfig2 { 
    @Before 
    public void justForCucumberToPickupThisClass(){} 
} 

第二種方法是到使用支持多個配置定製黃瓜轉輪。你可以自己寫或準備一個,例如,我的 - CucumberJar.java和項目cucumber-junit的根。 在這種情況下黃瓜亞軍將是這樣的:

CucumberJarRunner.java

@RunWith(CucumberJar.class) 
@CucumberOptions(glue = {"com.abc.common"}, 
     tags = {"[email protected]"}, 
     plugin = {"json:target/cucumber/cucumber-report-common.json"}) 
@CucumberGroupsOptions({ 
     @CucumberOptions(glue = {"com.abc.def"}, 
       features = {"classpath:com/abc/def/", 
         "classpath:com/abc/common.feature"} 
     ), 
     @CucumberOptions(glue = {"com.abc.ghi"}, 
       features = {"classpath:com/abc/ghi/", 
         "classpath:com/abc/common.feature"} 
     ) 
}) 
public class CucumberJarRunner { 
} 
+0

哇,感謝您的!這是有點晚了,我到現在實現這個視後正好一歲,但下一次我必須做同樣的事情,我會記住這一點:d – Kilian

+0

毫米,由於某種原因,我認爲這是今年以來的問題:) – nahab

相關問題