[英]Run scenarios in a cucumber feature file in parallel, one feature file at a time
[英]How to Run cucumber Feature files in parallel
我想運行功能文件(不是場景)以並行運行。
第一個特點:
Feature: Refund item for Jeff
Scenario: 01 Collect Details
Given Collect Jeff details
And Collect receipts for purchase
Scenario: 02 Refund
When Jeff returns the microwave
Then Jeff should be refunded $100
第二個特點:
Feature: Refund item for Dave
Scenario: 01 Collect Details
Given Collect Dave details
And Collect receipts for purchase
Scenario: 02 Refund
When Dave returns the microwave
Then Dave should be refunded $100
我正在使用帶有 testng 的 Cucumber-java。 我能夠並行運行這些場景。 但我真的很想並行運行功能。 我已經為並行場景實現了下面的代碼。
public class RunCucumberTest extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
你不能。 場景旨在彼此獨立地執行。 根據您要測試的內容,您可以將功能文件中的所有場景轉換為單個場景。
但是,您應該考慮重寫您的場景,使它們不依賴於先前場景中的操作。
通常這意味着編寫如下場景:
Scenario: Do a thing
Given a thing
When a thing is used
Then something happens
Scenario: Do another thing next
Given a thing that was used
When a thing is used again
Then something else happens
要實現a thing that was used
您可以重用您已經編寫的方法來實現第一個場景的步驟。
您無法使用TestNg
實現這一目標。 但。 您可以使用JUnit4
來實現。 基本上這就是根據Cucumber 規范對JUnit 4
進行並行化的方式。
Cucumber 可以使用 JUnit 和 Maven 測試執行插件並行執行。 在 JUnit 中,功能文件是並行運行的,而不是場景,這意味着一個功能文件中的所有場景都將由同一個線程執行。 您可以使用 Maven Surefire 或 Failsafe 插件來執行運行器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.