functional_test_generator

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Functional Test Generator (pkg/core/tools/functional_test_generator)

The Functional Test Generator creates distinct test scenarios from the API Knowledge Graph using various strategies.

Key Tool: generate_functional_tests

This tool generates and optionally executes comprehensive functional tests.

features
  • Strategies:
    • Happy Path: Valid requests with random valid data.
    • Negative: Invalid inputs, missing fields, wrong types.
    • Boundary: Edge cases, min/max values.
  • Filtering: Target specific endpoints or strategies.
  • Export: Automatically saves a Markdown report of all generated scenarios to .falcon/reports/functional_report_<timestamp>.md.

Usage

Use this tool to rapidly create a test suite from your API specification.

Example Prompts

Trigger this tool by asking:

  • "Generate a full suite of functional tests for the User API."
  • "Create negative test scenarios for the /login endpoint."
  • "I need boundary tests for the simplified order processing flow."
  • "Generate and run happy path tests for all GET endpoints."

Documentation

Overview

Package functional_test_generator provides spec-driven functional test generation for ZAP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportScenarios

func ExportScenarios(falconDir string, scenarios []shared.TestScenario) (string, error)

ExportScenarios exports test scenarios to a Markdown report.

Types

type BoundaryStrategy

type BoundaryStrategy struct{}

BoundaryStrategy generates test cases with boundary values.

func (*BoundaryStrategy) Generate

func (s *BoundaryStrategy) Generate(endpointKey string, analysis shared.EndpointAnalysis, baseURL string) []shared.TestScenario

Generate creates boundary test scenarios.

func (*BoundaryStrategy) Name

func (s *BoundaryStrategy) Name() string

type ExportTemplate

type ExportTemplate struct {
	Language string // go, javascript, python, etc.
	Format   string // framework-specific (e.g., jest, pytest, etc.)
}

ExportTemplate generates exportable test code templates. This is a placeholder for future implementation where we can generate actual test code files (e.g., Go test files, Jest tests, pytest, etc.)

func (*ExportTemplate) GenerateTestFile

func (t *ExportTemplate) GenerateTestFile(scenarios []shared.TestScenario, outputPath string) error

GenerateTestFile creates executable test code from scenarios. Future implementation for Sprint 5.4

type FunctionalTestGeneratorTool

type FunctionalTestGeneratorTool struct {
	// contains filtered or unexported fields
}

FunctionalTestGeneratorTool generates comprehensive functional tests from the API Knowledge Graph using various testing strategies.

func NewFunctionalTestGeneratorTool

func NewFunctionalTestGeneratorTool(falconDir string, executor *shared.TestExecutor) *FunctionalTestGeneratorTool

NewFunctionalTestGeneratorTool creates a new functional test generator tool.

func (*FunctionalTestGeneratorTool) Description

func (t *FunctionalTestGeneratorTool) Description() string

Description returns the tool description.

func (*FunctionalTestGeneratorTool) Execute

func (t *FunctionalTestGeneratorTool) Execute(args string) (string, error)

Execute generates functional tests from the Knowledge Graph.

func (*FunctionalTestGeneratorTool) Name

Name returns the tool name.

func (*FunctionalTestGeneratorTool) Parameters

func (t *FunctionalTestGeneratorTool) Parameters() string

Parameters returns the tool parameter description.

type GenerateParams

type GenerateParams struct {
	BaseURL    string   `json:"base_url"`             // Base URL for API (e.g., http://localhost:3000)
	Strategies []string `json:"strategies,omitempty"` // List of strategies (happy, negative, boundary). Empty = all
	Endpoints  []string `json:"endpoints,omitempty"`  // Specific endpoints to test. Empty = all endpoints
	Execute    bool     `json:"execute"`              // Whether to execute tests immediately
	Export     bool     `json:"export,omitempty"`     // Whether to export test scenarios to file
}

GenerateParams defines the parameters for test generation.

type GenerateResult

type GenerateResult struct {
	TotalScenarios int                 `json:"total_scenarios"`
	GeneratedBy    map[string]int      `json:"generated_by_strategy"` // strategy -> count
	Results        []shared.TestResult `json:"results,omitempty"`     // Only if Execute=true
	ExportPath     string              `json:"export_path,omitempty"` // Only if Export=true
	Summary        string              `json:"summary"`
}

GenerateResult represents the output of test generation.

type HappyPathStrategy

type HappyPathStrategy struct{}

HappyPathStrategy generates valid test cases with correct data.

func (*HappyPathStrategy) Generate

func (s *HappyPathStrategy) Generate(endpointKey string, analysis shared.EndpointAnalysis, baseURL string) []shared.TestScenario

Generate creates happy path scenarios with valid data for every endpoint.

func (*HappyPathStrategy) Name

func (s *HappyPathStrategy) Name() string

type NegativeStrategy

type NegativeStrategy struct{}

NegativeStrategy generates invalid test cases with missing/wrong data.

func (*NegativeStrategy) Generate

func (s *NegativeStrategy) Generate(endpointKey string, analysis shared.EndpointAnalysis, baseURL string) []shared.TestScenario

Generate creates negative test scenarios with invalid data.

func (*NegativeStrategy) Name

func (s *NegativeStrategy) Name() string

type ScenarioTemplate

type ScenarioTemplate struct {
	Name        string
	Description string
	Method      string
	URL         string
	Headers     map[string]string
	Body        string
	Assertions  []string
}

ScenarioTemplate represents a template for a test scenario.

func (*ScenarioTemplate) ToGoTest

func (st *ScenarioTemplate) ToGoTest() string

ToGoTest generates Go test code (example for future implementation).

type Strategy

type Strategy interface {
	// Generate creates test scenarios for a given endpoint.
	Generate(endpointKey string, analysis shared.EndpointAnalysis, baseURL string) []shared.TestScenario
	Name() string
}

Strategy defines the interface for test generation strategies.

type StrategyEngine

type StrategyEngine struct {
	// contains filtered or unexported fields
}

StrategyEngine is responsible for generating test scenarios based on different strategies.

func NewStrategyEngine

func NewStrategyEngine() *StrategyEngine

NewStrategyEngine creates a new strategy engine with all available strategies.

func (*StrategyEngine) Generate

func (e *StrategyEngine) Generate(
	endpointKey string,
	analysis shared.EndpointAnalysis,
	baseURL string,
	strategyName string,
) []shared.TestScenario

Generate creates test scenarios using the specified strategy.

type TestGenerator

type TestGenerator struct {
	// contains filtered or unexported fields
}

TestGenerator executes generated test scenarios using the shared TestExecutor.

func NewTestGenerator

func NewTestGenerator(executor *shared.TestExecutor) *TestGenerator

NewTestGenerator creates a new test generator.

func (*TestGenerator) ExecuteScenarios

func (g *TestGenerator) ExecuteScenarios(scenarios []shared.TestScenario) []shared.TestResult

ExecuteScenarios runs all test scenarios sequentially and returns the results. Scenarios must have fully qualified URLs (base_url already prepended).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL