Skip to content

API Mocking

Build comprehensive test scenarios without real environments

What is API Mocking?

When real APIs are unavailable, AngusTester's mocking feature creates virtual interfaces with identical behaviors, ensuring uninterrupted testing activities. You can:

✅ Mock any status code response
✅ Customize response delays
✅ Return different results based on request parameters
✅ Construct complex business scenarios
✅ Validate asynchronous processing logic

Core Capabilities Explained

1. Behavior Simulation

Create virtual objects to replace real dependencies and isolate test units

  • Simulate service unavailability
  • Construct specific business rule responses
  • Reproduce edge-case scenarios

2. Dependency Isolation

Eliminate risks associated with external system dependencies

  • Mock third-party API responses
  • Isolate bank/payment gateway testing
  • Virtualize external authentication services

3. Customized Responses

Dynamically return responses based on request parameters

yaml
responses:  
  - match:  
      parameters:  
        - name: userType  
          expected: "vip"  
    content:  
      status: 200  
      content: '{"level": "VIP", "discount": 0.8}'

4. Exception Scenario Testing

Construct various error conditions to validate system robustness

yaml
content:  
  status: 500  
  delay:  
    mode: RANDOM  
    minRandomTime: 1s  
    maxRandomTime: 5s

5. Asynchronous Flow Validation

Test asynchronous processing capabilities via callback mechanisms

yaml
responses:  
  - content:  
      callbackUrl: http://your-system/notify  
      callbackMethod: POST

API Mocking Application Examples

Benchmark Performance Testing Mock

yaml
task:  
  mockApis:  
    - method: GET  
      endpoint: /benchmark  
      responses:  
        - content:  
            status: 200  
            content: Success

Business Latency Testing Mock

yaml
responses:  
  - match:  
      parameters:  
        - name: delay  
          expected: "10"  
    content:  
      delay:  
        mode: FIXED  
        fixedTime: 10ms  
      content: '{"msg": "10ms delayed response"}'

User Login Business Mock

yaml
responses:  
  - match:  
      body: '{"username":"admin","password":"admin"}'  
    content:  
      status: 200  
      content: '{"code":"S","token":"181622ea2a1f4934..."}'  
  - content:  
      status: 400  
      content: '{"code":"E0","msg":"Invalid credentials"}'

File Download Mock

yaml
responses:  
  - content:  
      status: 200  
      headers:  
        - name: Content-Type  
          value: image/jpeg  
      contentEncoding: gzip_base64  
      content: <Binary file content>

Configuration Workflow

  1. Navigate to "Mock" → "Create Service"
  2. Add new interfaces or import mock scripts
  3. Restart service or refresh instance interfaces

Released under the GPL-3.0 License.