线上第六期_接口测试用例数据驱动与高级断言

课程知识点

参考代码

mvn的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>hgwz.testerhome.com</groupId>
    <artifactId>RestAssuredDemo20180414</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>

        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.6.1</version>
        </dependency>

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-java-client</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>



    </dependencies>

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <dependency.locations.enabled>false</dependency.locations.enabled>
    </properties>
</project>

jsonpath

package online6;

import org.junit.BeforeClass;
import org.junit.Test;

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class TesterHomeTest {
    @BeforeClass
    public static void beforeClass(){
        useRelaxedHTTPSValidation();
    }
    @Test
    public void topics(){
        given()
                .when().get("https://testerhome.com/api/v3/topics.json").prettyPeek()
        .then()
                .body("topics.id[0]", equalTo(15159))
                .body("topics[-1].user.login", equalTo("1q2q3q"))
                .body("topics.find {it.id == 14914}.title",
                        equalTo("基于 uiautomatorviewer 自动生成代码 (兼容 android 和 iOS)  "))
        ;
    }
}

python搭建mini网站

python -m CGIHTTPServer

参考连接

http://static.javadoc.io/io.rest-assured/json-path/3.1.0/io/restassured/path/json/JsonPath.html
http://static.javadoc.io/io.rest-assured/xml-path/3.1.0/io/restassured/path/xml/XmlPath.html

课后作业