No Code API Testing

This feature is available on all Testfully plans. You can set and run no-code tests using the Testfully Web app, Desktop app, Testfully CLI and API monitoring.

Ensuring that your API responds correctly is crucial when you are testing your API. This guide will explore how Testfully allows users to validate API responses without writing a single line of code, focusing on its intuitive JSON-based validation system.

Validation Across Environments in Testfully

In API testing, No-Code Validation, such as that provided by tools like Testfully, plays a crucial role in ensuring the integrity of API responses across various environments. Here's how it works:

  1. Universal Validation:

    • Purpose:: Applies across all testing environments (development, staging, production).
    • Benefit: Ensures that fundamental response criteria are consistently met, enhancing reliability.
  2. Environment-Specific Validation:

    • Purpose: Tailors validations to the unique characteristics of each environment.
    • Benefit: Provides flexibility to accommodate different response requirements or behaviors seen in specific stages like staging or production.
  3. Combined Approach:

    • Approach: Combination of Universal and Environment-Specific Validations.
    • Outcome: Establishes a comprehensive testing framework, balancing standard criteria with environment-specific needs, ensuring thorough validation of API responses.

Basic Response Validation

You can validate an API response using Testfully by entering the expected response. This straightforward method is ideal for quick validations. Users input their anticipated response and Testfully ensure that the API's response matches this expectation. It's important to note that this validation process is Case-Sensitive.

For example:

Let's try sending a POST request to https://httpbin.org/anything with the following data as the Request body:

{
  "name": "Rick Sanchez",
  "status": "Alive",
  "species": "Human",
  "gender": "Male"
}

As you know, when you POST any JSON data to this API endpoint, it returns the same, so we expect the return value to be the same as below:

{
  "json": {
    "name": "Rick Sanchez",
    "status": "Alive",
    "species": "Human",
    "gender": "Male"
  }
}

Validating arrays

Testfully supports validating arrays as well. For example, if you expect an array of objects in the response, you can validate it using the following JSON:

{
  "json": [
    {
      "name": "Rick Sanchez",
      "status": "Alive",
      "species": "Human"
    },
    {
      "name": "Morty Smith",
      "status": "Alive",
      "species": "Human"
    }
  ]
}

The example above shows how Testfully can validate a nested array of objects in the response. You can use the same syntax to validate root-level arrays as well. For example, if you expect the response to be an array of strings, you can use the following JSON:

["Rick Sanchez", "Morty Smith"]

Same way, you can validate an array of numbers, booleans, objects or any other data type.

Support for Complex Data Structures

Testfully's validation capabilities extend to handling nested JSON structures and arrays. It is a valuable feature when dealing with APIs that return complex data. Users can validate intricate API responses, including nested objects and arrays, ensuring a thorough and accurate validation process.

For example:

Let's try https://httpbin.org/anything again and POST this JSON as the Request body:

{
  "name": "Earth (C-137)",
  "type": "Planet",
  "dimension": "Dimension C-137",
  "residents": [
    {
      "name": "Rick Sanchez",
      "status": "Alive",
      "species": "Human",
      "gender": "Male"
    },
    {
      "name": "Morty Smith",
      "status": "Alive",
      "species": "Human",
      "gender": "Male",
      "location": {
        "name": "Citadel of Ricks"
      }
    },
    {
      "name": "Beth Smith",
      "status": "Alive",
      "species": "Human",
      "gender": "Female"
    }
  ]
}

and we can use this JSON for validation:

{
  "json": {
    "name": "Earth (C-137)",
    "type": "Planet",
    "dimension": "Dimension C-137",
    "residents": [
      {
        "name": "Rick Sanchez",
        "status": "Alive",
        "species": "Human",
        "gender": "Male"
      },
      {
        "name": "Morty Smith",
        "status": "Alive",
        "species": "Human",
        "gender": "Male",
        "location": {
          "name": "Citadel of Ricks"
        }
      },
      {
        "name": "Beth Smith",
        "status": "Alive",
        "species": "Human",
        "gender": "Female"
      }
    ]
  }
}

Validating Partial Responses

In addition to validating all responses, Testfully offers the flexibility to validate only a subset of the API response. It is handy when users are interested in specific parts of the response. By providing a subset of the expected response as input, Testfully focuses on validating only those elements, ignoring the rest. This selective validation is a powerful tool for users who need to target specific data within a more significant response, making their testing process more efficient and focused.

For example, for the above Request, we want to validate only the residents array in the response data; here is what our JSON for validation would look like:

{
  "json": {
    "residents": [
      {
        "name": "Rick Sanchez",
        "status": "Alive",
        "species": "Human",
        "gender": "Male"
      },
      {
        "name": "Morty Smith",
        "status": "Alive",
        "species": "Human",
        "gender": "Male",
        "location": {
          "name": "Citadel of Ricks"
        }
      },
      {
        "name": "Beth Smith",
        "status": "Alive",
        "species": "Human",
        "gender": "Female"
      }
    ]
  }
}

Schema Validation or Contract Testing

Schema Validation, also known as Contract Testing, is an essential aspect of API testing that focuses on verifying the structure of the API response rather than its content. This approach is crucial for ensuring that the API sticks to the expected format, enhancing the robustness and reliability of your API integration. In Testfully, Schema Validation is implemented through a user-friendly, JSON-based syntax. It allows users to define the expected data types of various response elements without specifying exact values. Here’s how you can use Testfully’s schema validation:

Using Simple Syntax for Schema Validation

Testfully allows you to validate the data type of each field in your response. For example, if you expect a field to always return a string, you can use the $string validator. The syntax is intuitive and easy to use, as shown in this example:

{
  "name": "$string",
  "age": "$number",
  "isActive": "$boolean",
  "address": {
    "street": "$string",
    "zipcode": "$number"
  },
  "tags": "$any",
  "status": "$null",
  "api_key": "$missing"
}

In this schema, name and street are expected to be strings, age and zipcode as numbers, isActive as a boolean, and tags can be of any type. Testfully supports advanced validators like $null for null values, $missing for fields that should not be present, and $any for fields where any value type is acceptable.

Advanced Syntax for Multiple Validators

For more complex scenarios where a field may need to pass multiple validations, Testfully offers an advanced syntax. This syntax allows the assignment of multiple validators to a single field. Here’s how it looks:

{
  "name": {
    "$string": true
  },
  "age": {
    "$number": true
  },
  "isActive": {
    "$boolean": true
  },
  "tags": {
    "$any": true
  },
  "api_key": {
    "$missing": true
  },
  "status": {
    "$null": true
  },
  "address": {
    "street": {
      "$string": true
    },
    "zipcode": {
      "$number": true
    }
  }
}

Schema validation for array elements

Testfully also supports schema validation for array elements. For example, if you expect an array of objects in the response, you can validate it using the following JSON:

{
  "json": [
    {
      "name": "$string",
      "age": "$number",
      "isActive": "$boolean"
    }
  ]
}

In this example, the schema validates that each object in the array has a name field of type string, an age field of type number, and an isActive field of type boolean. The same syntax can be used to validate root-level arrays as well. For example, if you expect the response to be an array of strings, you can use the following JSON:

["$string"]

Supported Validators

ValidatorUsage
$stringUse "$string" to validate value of a field being string (any string)
$numberUse "$number" to validate value of a field being number (any number)
$booleanUse "$boolean" to validate value of a field being boolean (true or false)
$anyUse "$any" to validate that the value is anything
$nullUse "$null" to validate that the value of the field will be null
$missingUse "$missing" to validate that the defined field won't be available at all

Step-by-Step Example Using httpbin.org

Let's start by adding validations:

  1. Open Testfully and add a new Request; set the URL to https://httpbin.org/anything. This endpoint echoes the HTTP request data, making it ideal for testing.
  2. Choose the POST method and enter JSON data in the request body. For example:
{
  "name": "Jane Doe",
  "age": 30,
  "isActive": true
}
  1. Select Validation
  2. Click on Add Environment button and
    • Select All Environments to validate your API response regardless of the selected environment. Remember, these rules are a constant check, ensuring API responses meet every environment's basic criteria.
    • Select a particular Environment to validate your API response only when the very environment is selected.
    • Or you can combine the two options by providing a set of validations for All Environments and a set of validations for each desired environment.
  3. In front of Response Code, we will set it to 200.
  4. In front of Response Time, you can set the expected response time.
  5. In front of Response Body, apply the schema validation rules. For example:
{
  "json": {
    "name": "$string",
    "age": "$number",
    "isActive": "$boolean"
  }
}
  1. Select your preferred environment and click on Send
  2. Observe how Testfully validates the Response based on the defined schema in the Response Validations section.