Overview of Karate
mainKarate is an open-source unified framework designed to combine several testing disciplines into a single tool. It supports:
- API testing
- Mocks
- Performance testing
- UI automation
repository·main·Indexed 26 days ago
https://github.com/karatelabs/karateA unified open-source testing framework that integrates API testing, service mocking, performance testing, and UI automation. It includes karate-core for HTTP clients and servers, a Thymeleaf-based Markup engine, a JSON/XML assertion library (Match), and karate-js for executing ES6 JavaScript on the JVM. Additionally, the karate-image extension provides visual comparison capabilities with support for resemble and ssim engines and an interactive report lightbox for debugging.
Karate is an open-source unified framework designed to combine several testing disciplines into a single tool. It supports:
Karate v2 is a unified test automation framework that combines API testing, mocking, and performance testing. It is built on Java 21+ and features a custom, thread-safe JavaScript engine designed for parallel execution.
Key capabilities include:
The karate-core framework consists of several specialized modules:
io.karatelabs.io.http): Provides an Apache HttpClient-based client (with request builder) and a Netty-based server. Supports Basic, Bearer, and OAuth2 (Client Credentials, Authorization Code with PKCE) authentication, session management with cookies, and CSRF protection.io.karatelabs.markup): A Thymeleaf-based engine featuring a custom Karate Dialect, built-in HTMX support, and integration with the karate-js engine.io.karatelabs.match): An assertion library for JSON (with wildcards), XML, schema validation, and fuzzy matching.io.karatelabs.core): Includes ScenarioRuntime for test execution and KarateJs as a bridge to the JavaScript engine.The karate-js engine is a lightweight, thread-safe JavaScript engine implemented in Java. It targets idiomatic ES6 and has minimal dependencies (SLF4J and JSON-smart).
Core packages include:
io.karatelabs.js: Core JavaScript engine (interpreter, runtime, built-in types).io.karatelabs.parser: Parsing infrastructure (lexer, parser, AST nodes).io.karatelabs.common: Shared utilities (file, OS, string operations).The Karate match engine (io.karatelabs.match) performs deep comparisons and collects all mismatches in a single pass rather than failing on the first one. This allows for fixing multiple errors in one iteration.
It supports Fuzzy Markers for schema-like validation:
#string, #number, #null, #notpresent#regex(...)#?<expr> (JS predicate)## (optional marker)$ (cross-field references)The Karate v2 CLI uses a two-tier architecture to separate system management from test execution:
karate binary): Handles installation and management tasks. It provides commands for setup, update, config, init, doctor, and version.io.karatelabs.Main): Handles runtime execution and test features. It receives arguments from the Rust launcher and provides commands for run, mock, clean, and init (note: init is implemented in Rust to scaffold projects before the JVM is required).Use the Rust launcher for environment setup and the Java CLI for running your actual test suites.
The Karate Extension SPI is currently in a forward-looking design phase. Note the following current limitations and design decisions:
ServiceLoader. You must explicitly activate an extension using boot.ext('name').ReportAssets interface currently supports only a single .js() and .css() file per extension. If your extension requires multiple files, you must concatenate them into a single bundle.* image.threshold = 0.02) and JS method calls (e.g., * def r = image.compare(...)). Advanced DSL features like JSON-arg dispatch or Cucumber-like pattern matching are planned but not yet implemented.karate or read), registering an extension global that shares a name with a user-defined variable (def) may cause shadowing issues.The Karate v2 design documentation provides specialized guides for advanced usage and extension. Depending on your goal, you should refer to the following specific documentation files:
karate-pom.json.registerEmbed UI hook.JsValue hierarchy, Java interop, and prototypes.The karate-gatling module allows for performance testing by integrating Karate's functional testing capabilities with the Gatling engine.
Key Integration Details:
__karate or __gatling prefix. Note that unprefixed top-level access is a breaking change from v1.PerfHook.submit().--format json).--simulation class support).Karate's execution model follows a hierarchical structure: a Suite orchestrates the execution, which manages FeatureRuntime instances. Each feature contains ScenarioRuntime instances, which in turn use a StepExecutor to dispatch actions. The StepExecutor interacts with specialized engines for matching, HTTP communication, and other actions.
Suite → FeatureRuntime → ScenarioRuntime → StepExecutor
↓
┌────────────────┼────────────────┐
▼ ▼ ▼
Match Engine Http Client Other ActionsThe karate-js engine follows several core design principles to ensure performance and compatibility:
CallInfo) are only created when necessary (e.g., during new operations).getJavaValue().typeof, instanceof, and truthiness match the official JavaScript specification.getJavaValue() method is designed to return idiomatic Java types.getJsValue() to unwrap JsValue types before performing type switches on raw types.fromThis(Context) pattern across all JsObject subclasses to resolve the execution context.