2017-10-18 117 views
3

我的項目有兩個不同的黃瓜測試,每個人都需要不同的春天上下文配置。Intellij,黃瓜測試和兩個春天上下文配置

我遇到的問題是,當我從Intellij單獨運行每個測試時,它們會加載正確的Spring上下文並且測試正在通過,但是我按下了運行所有測試,沒有一個通過。

運行一個maven測試,兩個測試都通過了。

這是我的代碼:

@RunWith(FCSCucumber.class) 
 
@Cucumber.Options(strict = true 
 
//  , tags = {"[email protected]"} 
 
//  , tags = {"@Only"} 
 
     , glue ="feature.scenario1" 
 
     , features = "src/test/resources/feature/scenario1/" 
 
) 
 
@FCSApplicationProperties(commonProps="config/scenario1/exec.common.properties", 
 
     environmentProps="src/test/resources/scenario1-test.properties") 
 
public class TesScenario1Features { 
 
\t 
 
}

@ContextConfiguration("/cucumber-scenario1.xml") 
 
public class scenario1Steps { 
 
...... 
 
}

@RunWith(FCSCucumber.class) 
 
@Cucumber.Options(strict = true 
 
//  , tags = {"[email protected]"} 
 
//  , tags = {"@Only"} 
 
     , glue ="feature.scenario2" 
 
     , features = "src/test/resources/feature/scenario2/" 
 
) 
 
@FCSApplicationProperties(commonProps="config/scenario2/exec.common.properties", 
 
     environmentProps="src/test/resources/scenario2-test.properties") 
 
public class TesScenario2Features { 
 
\t 
 
}

@ContextConfiguration("/cucumber-scenario2.xml") 
 
public class scenario2Steps { 
 
...... 
 
}

非常感謝您的幫助

回答

1

的問題是IntelliJ cucumber plugin使用cucumber cli運行測試,而無需使用JUnit運行在所有。這會導致一些限制,例如在步驟定義類而不是運行器上需要Spring註釋,或者默認情況下要求步驟定義與場景文件位於同一個包中。

在你的例子中,我實際上希望運行單個測試失敗,除非正確的應用程序屬性也被/cucumber-scenario{1,2}.xml文件引用。

我看到的標準黃瓜實現的唯一選擇是將測試提取到單獨的項目中。

我實際上正在研究alternative implementation of cucumber,您可能想嘗試改進彈簧集成。但它尚未與IntelliJ完全集成。