k6

A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Guides

check( val, sets, [tags] )

Run checks on a value. A check is a test condition that can give a truthy or falsy result. The sets parameter contain one or more checks, and the check() function will return false if any of them fail.

Note that checks are not asserts in their traditional sense - a failed assertion will throw an error, while a check will always return with a pass or a failure. Failure conditions can then instead be controlled by thresholds, for more power and flexibility.

Parameter
Type
Description

val

any

Value to test.

sets

object

Tests (checks) to run on the value.

tags (optional)

object

Extra tags to attach to metrics emitted.

Returns:

Type
Description

boolean

Returns true if all checks have succeeded, otherwise false.

import http from "k6/http";
import { check } from "k6";

export default function() {
  let res = http.get("http://httpbin.org");
  check(res, {
    "response code was 200": (res) => res.status == 200,
    "body size was 1234 bytes": (res) => res.body.length == 1234,
  });
};

Using check() to verify that an HTTP response code was 200 and that body was 1234 bytes

check( val, sets, [tags] )


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.