[英]How to skip tests that hangs/stuck during execution Selenium - Maven - Jenkins
我想請您協助解決我的問題。 我有包含50個測試腳本的Regression Suite(.xml)。 我們可以使用Maven在Jenkins中執行回歸套件,但是它突然掛起/卡住了。 例如:
測試用例1-15已完成,但是在測試用例16中時,構建/執行突然停滯/掛在某個步驟上。 我試圖在Eclipse中執行測試用例16,以了解哪個步驟/代碼有問題,但是它工作正常。
我想問一下是否有一個maven-surefire功能,當它檢測到測試腳本卡住/掛起了一定的分鍾數(例如5分鍾)時,它將使該測試腳本失敗,然后繼續執行下一個。
請看下面我的pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<inherited>true</inherited>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>${xmlPath}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
您可以在測試本身的測試注釋中添加超時:
@Test(timeout=600000) //Fails if the method takes longer than 10 minutes
它以毫秒為單位,因此您只需要確定測試應花費的最長時間,然后從那里進行計算
編輯:如果只想設置一次而不必將超時添加到每個單獨的測試,則可以在基類中設置一個規則:
import org.junit.Rule;
import org.junit.rules.TestWatcher;
...
@Rule
public TestWatcher watcher = new TestWatcher() {
@Override
public Statement apply(Statement base, Description description) {
if (description.getMethodName().toLowerCase().contains("thisTestTakesLonger")) {
return new FailOnTimeout(base, 600000); //10 minutes = 600000
} else {
return new FailOnTimeout(base, 300000); //5 minutes = 300000
}
}
};
else是全局超時,如果是單個測試花費更長的時間,則為if(如果每個測試的長度大約相同,則可能只需要else中的位)
通過在pom.xml中將此屬性設置為true,可以使maven忽略測試失敗
<testFailureIgnore>true</testFailureIgnore>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.