簡體   English   中英

REST上的許多GET請求得到保證-JAVA

[英]Many GET request on REST assured - JAVA

我有一些URL的列表字符串:

  • localhost:80/my/first/url
  • localhost:80/my/second/url

可以有2個,5個或更多網址。 我必須檢查哪個廣告客戶回答了錯誤500。

@Test()  //bad test
public void checkErrorStatusForURLs() {
    for(String url : urlList()) {
        given().when().get(url)
               .then().statusCode(CoreMatchers.not(500));
    }
}

我不想為每個網址編寫測試。 我可以通過一項測試嗎? 如何正確做?

您可以提取statusCode,然后檢查所需的evere條件,如下所示:

for(String url : urlList()) {
    int statusCode = given().when().get(url).then().extract().statusCode();
    if(500 == statusCode) {
        //add it to a list??
    }
}

看看這里描述的Junit 4的參數化測試: https : //github.com/junit-team/junit4/wiki/parameterized-tests

類似的方法可能對您有用:

@RunWith(Parameterized.class)
public class FibonacciTest {

@Parameters
public static Iterable<? extends Object> urls() {
    return Arrays.asList("localhost:80/my/first/url", "localhost:80/my/second/url" );
}

@Parameter 
public /* NOT private */ String url;

@Test
public void checkErrorStatusForURLs() {
        given().when().get(url)
               .then().statusCode(CoreMatchers.not(500));
 ...
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM