Backend Development 7 min read

FunTester moco: Architecture and Feature Overview of the moco API Testing Framework

This article introduces the FunTester moco framework, summarizing its architecture, the three core components (RequestMatcher, ResponseHandler, HttpServer), detailed matching and response capabilities, and additional utilities such as runners and monitoring, providing a comprehensive guide for developers using the moco API.

FunTester
FunTester
FunTester
FunTester moco: Architecture and Feature Overview of the moco API Testing Framework

Previously I posted two architecture diagrams for the FunTester testing framework, which received good feedback; now I revisit the moco API and present a summary of its features wrapped in the FunTester moco framework.

The FunTester moco architecture is a consolidation of the moco API and is divided into three functional categories: RequestMatcher , ResponseHandler , and HttpServer .

RequestMatcher

This object is responsible for matching incoming requests and intercepting them before a response is generated.

Matching is split into three types: URL matching , parameter matching , and composite matching .

URL Matching

urlOnly: full URL match

urlStartsWith: URL prefix match

urlEndWith: URL suffix match

urlContain: URL contains match

urlMatcher: URL regex match

It also supports hidden request method matching for GET and POST , as well as put and delete methods.

Parameter Matching

Parameter matching considers both the source of the parameter and its attributes.

Parameter Sources

args: GET query parameters

params: POST JSON body parameters

form: POST form parameters

header: request header parameters

cookie: cookie parameters

Parameter Attributes

exist: whether the parameter exists

eq: whether the parameter value equals the expected value

Composite Matching

Three composite matching functions are provided: both (all conditions must be met), or (any condition met), and not (none of the conditions met).

ResponseHandler

After RequestMatcher intercepts a request, ResponseHandler generates the response, which is categorized into four types:

Basic Responses

textRes: text content

jsonRes: JSON content

obRes: object content

These form the foundation for advanced responses.

Functional Responses

cycleRes: cyclic response, rotating through a list of configured responses

sequenceRes: sequential response, progressing through an ordered array and staying on the last item thereafter

random: random response, selecting one of the configured responses at each request

Setting Responses

setStatus: set HTTP status code

setHeader: set response header

setCookie: set cookie

setProxy: set proxy URL and return the proxied content

Extended Responses

delay: delayed response

QPS: fixed queries per second

limit: limit request frequency

cycle: similar to functional response but with more configurable content

HttpServer

This component has few settings; besides request method configuration, it mainly provides the MocoMonitor with port and log options, which are concrete implementations within the moco API ecosystem.

Two important settings are:

proxy: sets a redirect proxy (different from the proxy in ResponseHandler )

mount: sets a mount point, similar to static site generation examples

The MocoRequestHit class tracks hit counts for each interface, useful for validating request frequencies.

Runner is a special component used to start and stop services; a single Runner can manage multiple HttpServer instances, allowing flexible control during runtime.

FunTester

FunTester is a recognized author on Tencent Cloud, Boss Zhipin, and GDevOps, focusing on testing development.

Backend Developmenttesting frameworkMocoAPI mockingrequest matcherresponse handler
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.