Help us shape the future of Go! Take the 2026 Go Developer Survey

testgen

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testgen generates executable test stubs from TPD (Test Plan Document).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() []string

Available returns all registered generator language names.

func Register

func Register(gen Generator)

Register adds a generator to the registry.

Types

type APITestCase

type APITestCase struct {
	Endpoint         string `json:"endpoint"`
	Method           string `json:"method"`
	Scenario         string `json:"scenario"`
	ExpectedResponse string `json:"expected_response"`
	Priority         string `json:"priority"`
}

APITestCase represents an API-specific test case.

type GenerateOptions

type GenerateOptions struct {
	OutputDir     string // Output directory for generated files
	PackageName   string // Package/module name
	TestFramework string // testing, testify, jest, pytest
	GroupBy       string // type, file, priority
}

GenerateOptions configures test generation.

func DefaultOptions

func DefaultOptions() GenerateOptions

DefaultOptions returns sensible defaults for generation.

type GenerateResult

type GenerateResult struct {
	Language    string          `json:"language"`
	Framework   string          `json:"framework"`
	OutputDir   string          `json:"output_dir"`
	Files       []GeneratedFile `json:"files"`
	TotalTests  int             `json:"total_tests"`
	GeneratedAt time.Time       `json:"generated_at"`
}

GenerateResult contains the output of test generation.

type GeneratedFile

type GeneratedFile struct {
	Path      string `json:"path"`
	TestCount int    `json:"test_count"`
	Content   string `json:"-"` // Content not included in JSON
}

GeneratedFile represents a generated test file.

type Generator

type Generator interface {
	// Generate generates test stubs from parsed test cases.
	Generate(cases []TestCase, opts GenerateOptions) (*GenerateResult, error)

	// Language returns the target language name.
	Language() string
}

Generator defines the interface for test stub generators.

func Get

func Get(language string) (Generator, error)

Get retrieves a generator by language name.

type GoGenerator

type GoGenerator struct{}

GoGenerator generates Go test stubs.

func (*GoGenerator) Generate

func (g *GoGenerator) Generate(cases []TestCase, opts GenerateOptions) (*GenerateResult, error)

Generate creates Go test files from test cases.

func (*GoGenerator) Language

func (g *GoGenerator) Language() string

Language returns the language name.

type JourneyTestCase

type JourneyTestCase struct {
	Journey    string   `json:"journey"`
	Steps      []string `json:"steps"`
	Assertions []string `json:"assertions"`
	Priority   string   `json:"priority"`
}

JourneyTestCase represents a user journey test case.

type ParsedTPD

type ParsedTPD struct {
	FunctionalTests []TestCase        `json:"functional_tests"`
	APITests        []APITestCase     `json:"api_tests"`
	JourneyTests    []JourneyTestCase `json:"journey_tests"`
}

ParsedTPD contains all test cases parsed from a TPD document.

func (*ParsedTPD) AllTestCases

func (p *ParsedTPD) AllTestCases() []TestCase

AllTestCases returns all test cases as a flat list.

func (*ParsedTPD) TestsByPriority

func (p *ParsedTPD) TestsByPriority() map[string][]TestCase

TestsByPriority groups test cases by priority.

func (*ParsedTPD) TestsByType

func (p *ParsedTPD) TestsByType() map[TestType][]TestCase

TestsByType groups test cases by type.

type Parser

type Parser struct{}

Parser extracts test cases from TPD markdown documents.

func NewParser

func NewParser() *Parser

NewParser creates a new TPD parser.

func (*Parser) Parse

func (p *Parser) Parse(content string) (*ParsedTPD, error)

Parse extracts test cases from TPD markdown content.

type PythonGenerator

type PythonGenerator struct{}

PythonGenerator generates Python/pytest test stubs.

func (*PythonGenerator) Generate

func (g *PythonGenerator) Generate(cases []TestCase, opts GenerateOptions) (*GenerateResult, error)

Generate creates Python test files from test cases.

func (*PythonGenerator) Language

func (g *PythonGenerator) Language() string

Language returns the language name.

type TestCase

type TestCase struct {
	ID        string   `json:"id"`         // TC-001, API-001
	Title     string   `json:"title"`      // Test case title
	Type      TestType `json:"type"`       // functional, api, integration, e2e, performance
	Input     string   `json:"input"`      // Test input description
	Expected  string   `json:"expected"`   // Expected output/result
	Priority  string   `json:"priority"`   // P0, P1, P2
	Steps     []string `json:"steps"`      // Test steps
	SourceRef string   `json:"source_ref"` // REQ-XXX traceability
}

TestCase represents a single test case extracted from TPD.

type TestType

type TestType string

TestType represents the type of test case.

const (
	TestTypeFunctional  TestType = "functional"
	TestTypeAPI         TestType = "api"
	TestTypeIntegration TestType = "integration"
	TestTypeE2E         TestType = "e2e"
	TestTypePerformance TestType = "performance"
	TestTypeUAT         TestType = "uat"
)

type TypeScriptGenerator

type TypeScriptGenerator struct{}

TypeScriptGenerator generates TypeScript/Jest test stubs.

func (*TypeScriptGenerator) Generate

func (g *TypeScriptGenerator) Generate(cases []TestCase, opts GenerateOptions) (*GenerateResult, error)

Generate creates TypeScript test files from test cases.

func (*TypeScriptGenerator) Language

func (g *TypeScriptGenerator) Language() string

Language returns the language name.

Jump to

Keyboard shortcuts

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