2 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
假設(shè)您正在使用 maven 來(lái)運(yùn)行測(cè)試。
如果您打算使用 junit runner of Cucumber,您可以繼續(xù)使用現(xiàn)有邏輯來(lái)設(shè)置BeforeClassrunner 中的數(shù)據(jù)。如果你有一個(gè)跑步者會(huì)更容易,否則你需要在插件中設(shè)置執(zhí)行順序。關(guān)于跳過(guò) Given 方法,您可以向 中添加一個(gè)屬性surefire or failsafe plugin并在 Given 方法中使用它。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<systemProperties>
<property>
<name>skipproperty</name>
<value>myvaluetest</value>
</property>
</systemProperties>
</configuration>
</plugin>
在 Given 方法中,您可以使用此屬性作為跳過(guò)該步驟的標(biāo)志。雖然它是一個(gè)黑客,因?yàn)樗粡?fù)制到所有設(shè)置方法。但是這樣你仍然可以將邏輯保留在給定的方法中。而且,如果您刪除 POM 中的屬性,Cucumber 將按照正常方式進(jìn)行設(shè)置。
if(System.getProperty("skipproperty")!=null)
return;
但是,如果您還想嘗試使用 TestNg,則可以使用 mavenexec plugin來(lái)運(yùn)行設(shè)置代碼。這將使其獨(dú)立于測(cè)試框架。設(shè)置與上面相同,只是在 POM 中添加了 exec 插件。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>my-execution</id>
<phase>process-test-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>runner.ExecuteSetup</mainClass>
<classpathScope>test</classpathScope>
</configuration>
</plugin>
ExecuteSetup main()方法將包含調(diào)用設(shè)置代碼的現(xiàn)有邏輯。確保你添加classpathscope否則你會(huì)得到一個(gè)奇怪的classnotfoundexception.

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
我認(rèn)為您不能只在 Cucumber 中運(yùn)行所有給定的步驟,然后運(yùn)行其余的步驟。Cucumber 將一一運(yùn)行所有步驟。
添加回答
舉報(bào)