PacketFlow.Component.Testing (packetflow v0.1.0)

Component testing interfaces for automated testing

This module provides:

  • Component test suite generation
  • Integration testing utilities
  • Mock and stub implementations
  • Test data factories
  • Performance testing tools
  • Test reporting and analysis

Summary

Functions

Create a mock component for testing

Create test data factory for a component

Generate test report in various formats

Run integration tests between components

Run performance tests for a component

Run a single test case

Run a test suite

Types

test_case()

@type test_case() :: %{
  name: String.t(),
  description: String.t(),
  setup: function() | nil,
  test_function: function(),
  cleanup: function() | nil,
  timeout: integer(),
  tags: [atom()],
  metadata: map()
}

test_report()

@type test_report() :: %{
  suite: test_suite(),
  results: [test_result()],
  summary: %{
    total: integer(),
    passed: integer(),
    failed: integer(),
    skipped: integer(),
    timeout: integer(),
    total_duration_ms: number()
  },
  timestamp: integer()
}

test_result()

@type test_result() :: %{
  test_case: test_case(),
  status: :passed | :failed | :skipped | :timeout,
  duration_ms: number(),
  message: String.t() | nil,
  error: term() | nil,
  timestamp: integer()
}

test_suite()

@type test_suite() :: %{
  name: String.t(),
  component_id: atom(),
  test_cases: [test_case()],
  setup_all: function() | nil,
  cleanup_all: function() | nil,
  metadata: map()
}

Functions

create_mock_component(component_id, mock_config \\ %{})

@spec create_mock_component(atom(), map()) :: {:ok, pid()} | {:error, term()}

Create a mock component for testing

create_test_case(name, description, test_function, opts \\ [])

@spec create_test_case(String.t(), String.t(), function(), keyword()) :: test_case()

Create a test case

create_test_data_factory(component_type, options \\ %{})

@spec create_test_data_factory(atom(), map()) :: map()

Create test data factory for a component

create_test_suite(name, component_id, test_cases, opts \\ [])

@spec create_test_suite(String.t(), atom(), [test_case()], keyword()) :: test_suite()

Create a test suite for a component

generate_test_data(factory, data_type, overrides \\ %{})

@spec generate_test_data(map(), atom(), map()) :: term()

Generate test data using a factory

generate_test_report(report, format \\ :text)

@spec generate_test_report(test_report(), atom()) :: String.t() | map()

Generate test report in various formats

run_integration_tests(component_ids, test_cases)

@spec run_integration_tests([atom()], [test_case()]) :: test_report()

Run integration tests between components

run_performance_tests(component_id, test_config \\ %{})

@spec run_performance_tests(atom(), map()) :: map()

Run performance tests for a component

run_test_case(test_case)

@spec run_test_case(test_case()) :: test_result()

Run a single test case

run_test_suite(suite)

@spec run_test_suite(test_suite()) :: test_report()

Run a test suite