Testing

This guide covers best practices for testing NudgeLang applications.

Unit Testing

1. Basic Unit Tests

tests:
  - name: process_data_test
    type: unit
    tool: process_data
    input:
      data: "test_data"
    expected:
      output: "processed_data"
      status: "success"

2. Advanced Unit Tests

tests:
  - name: process_data_test
    type: unit
    tool: process_data
    input:
      data: "test_data"
    expected:
      output: "processed_data"
      status: "success"
    validation:
      - type: output_format
        schema: "output_schema.json"
      - type: performance
        max_duration: 1000
      - type: memory
        max_usage: 100

Integration Testing

1. Basic Integration Tests

tests:
  - name: api_integration_test
    type: integration
    states:
      - id: start
        type: initial
        next: api_call
      - id: api_call
        type: tool
        tool: external_api
        input:
          data: "test_data"
    expected:
      output:
        status: "success"
        data: "response_data"

2. Advanced Integration Tests

tests:
  - name: api_integration_test
    type: integration
    states:
      - id: start
        type: initial
        next: api_call
      - id: api_call
        type: tool
        tool: external_api
        input:
          data: "test_data"
    expected:
      output:
        status: "success"
        data: "response_data"
    validation:
      - type: response_time
        max_duration: 2000
      - type: error_handling
        scenarios:
          - input: "invalid_data"
            expected: "error_response"
          - input: "timeout_data"
            expected: "timeout_response"

End-to-End Testing

1. Basic E2E Tests

tests:
  - name: e2e_test
    type: e2e
    flow:
      - id: start
        type: initial
        next: process_data
      - id: process_data
        type: tool
        tool: process_data
        input:
          data: "test_data"
        next: validate_output
      - id: validate_output
        type: tool
        tool: validate_data
        input:
          data: "${output}"
    expected:
      final_status: "success"

2. Advanced E2E Tests

tests:
  - name: e2e_test
    type: e2e
    flow:
      - id: start
        type: initial
        next: process_data
      - id: process_data
        type: tool
        tool: process_data
        input:
          data: "test_data"
        next: validate_output
      - id: validate_output
        type: tool
        tool: validate_data
        input:
          data: "${output}"
    expected:
      final_status: "success"
    validation:
      - type: flow_completion
        max_duration: 5000
      - type: state_transitions
        expected:
          - from: start
            to: process_data
          - from: process_data
            to: validate_output
      - type: error_handling
        scenarios:
          - input: "invalid_data"
            expected: "error_flow"

Test Data Management

1. Basic Test Data

tests:
  - name: data_test
    type: unit
    tool: process_data
    test_data:
      input:
        - data: "test_case_1"
          expected: "result_1"
        - data: "test_case_2"
          expected: "result_2"
Last updated on