如何使用 testng 将我的放心测试更改为黄瓜?

问题描述

我一直在尝试使用 testng 将我放心的测试转移到黄瓜上,我几乎已经破解了它,但是这个断言让我有点担心。我遇到的这个问题是我断言中的主体抛出了这个错误。

java: cannot find symbol
  symbol:   method body(java.lang.String,org.hamcrest.Matcher<java.lang.String>)
  location: class stepdefs.articlesCucumberTests

这是我目前的工作测试。

import static io.restassured.RestAssured.*;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import static org.hamcrest.Matchers.*;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import org.testng.annotations.Test;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class articlesTestNg extends enablers {

    //Checks articles individual ID's.
    @Test(dataProvider = "getId")
    public void TestAllArticles(String articlesId) {

        given().
                given().log().all().and().
                pathParam("id",articlesId).
                when().
                get(singleArticles).
                then().
                assertThat().
                statusCode(200).
                body(("id"),equalTo(articlesId));
    }

    //Checks the whole content of the json file using an expected outcome in the project structure.
    @Test
    public void GetArticlesJson() {
        JsonPath expectedJson = new JsonPath(new File(pathJson));

        given().
                when().
                get(allArticles).
                then().
                assertThat().
                statusCode(200).
                and().
                body("",hasItem(expectedJson.getMap("")));
    }

这是我迄今为止对黄瓜测试的尝试,我将收到一篇文章,身体正在抛出错误。有没有更好的方法来做到这一点?

package stepdefs;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.junit.jupiter.api.Assertions;


import org.testng.Assert;
import org.testng.annotations.Test;
import skySportsPages.enablers;


import static io.restassured.RestAssured.baseURI;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;


public class articlesCucumberTests extends enablers {

    private Response response;

    @Test
    @Given("I have a set of articles containing individual ID's")
    public void i_have_a_set_of_articles_containing_individual_id_s() {
        RestAssured.baseURI = singleArticles;
        System.out.println(baseURI);
    }

    @Test(dataProvider = "getId")
    @When("I get an the article ID")
    public void i_get_an_the_article_id(String articlesId) {
        given().
                given().log().all().and().
                pathParam("id",articlesId).
                when().
                get(singleArticles);

    }
    @Test
    @Then("I will receive an individual article")
    public void i_will_receive_an_individual_article(String articlesId) {
        Assert.assertEquals(body(("id"),equalTo(articlesId)));

    }

    @Test
    @Given("I have a set of articles")
    public void i_have_a_set_of_articles(String articlesId) {

    }

    @Test
    @When("I get the list of articles")
    public void i_get_the_list_of_articles() {

    }
    @Test
    @Then("It will match the json file")
    public void it_will_match_the_json_file() {

    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)