使用Rest Assured的API Post请求和响应错误

时间:2017-02-26 06:15:38

标签: java api maven

我收到此帖子请求的错误,同时验证正文。我正在使用Maven和TestNG使用restassured框架。在使用@DataProvider时,我看到使用equalTo和containsOnly时出现的错误就像抛出错误一样。所有的想法都真的很感激。

使用@DataProvider的POST请求:

package com.inline.restassured;

import static io.restassured.RestAssured.given;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class FilePostToVirusTotal {

    static String baseURL = "https://www.test.com/tapi/v2/file/report";


    @DataProvider(name = "md5hashes")
    public String[][] createMD5TestData() {

        return new String[][] resource {

            {"md51", "928bc8b9661f0a1dc4eb3n2bdca48551"},
            {"md52", "928bc8b9661f0a1dc4eb3k2bdca48556"},
            {"md53", "928bc8b9661f0a1dc4eb3t2bdca48557"},
            {"md54", "928bc8b9661f0a1dclk903a2bdca4855"},
            {"md55", "928bc8b9661f0a1dc4eb3a2bdca48559"},

        };

    }

    @Test(dataProvider = "md5hashes")
    public void md5JsonTest(String apikey, String resource)
    {
        given().
                param("JSON", resource).
                param("JSON", "94567jhyeser").

        when().
                post(baseURL).
        then().
                assertThat().
                statusCode(200)
                .body("resource", equalTo(resource)) //the highlighted 'equalTo' is prompting as undefined.
                                .body("response_code", containsOnly(1, 0, -1));


    }


}


Sample Response :

{
  "response_code": 0,
  "resource": "928bc8b9661f0a1dc4eb3n2bdca48551",
}

0 个答案:

没有答案