Documentation
¶
Overview ¶
Package e2e 提供端到端测试框架
支持构建完整的 Agent 测试场景,包括输入、预期输出和验证。
主要组件:
- TestCase: 单个测试用例,包含多个测试步骤
- TestSuite: 测试套件,组合多个测试用例
- Runner: 测试运行器,支持顺序和并行执行
- TestResult/SuiteResult: 测试结果,包含通过/失败详情
使用示例:
suite := &e2e.TestSuite{
Name: "Agent 基础功能",
Cases: []*e2e.TestCase{
{
Name: "简单对话",
Steps: []e2e.Step{
{
Name: "发送消息",
Action: func(ctx context.Context) (any, error) {
return agent.Run(ctx, input)
},
Validate: func(result any) error {
// 验证结果
return nil
},
},
},
},
},
}
runner := e2e.NewRunner()
result := runner.RunSuite(ctx, suite)
fmt.Println(result)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner E2E 测试运行器
支持顺序和并行两种执行模式。 并行模式下,套件中的各用例会并发执行。
type RunnerOption ¶
type RunnerOption func(*Runner)
RunnerOption Runner 配置选项
func WithDefaultTimeout ¶
func WithDefaultTimeout(timeout time.Duration) RunnerOption
WithDefaultTimeout 设置默认超时
type Step ¶
type Step struct {
// Name 步骤名称
Name string
// Action 步骤动作,返回执行结果和错误
Action func(ctx context.Context) (any, error)
// Validate 验证函数,检查 Action 的结果是否符合预期
// 返回 nil 表示验证通过,返回 error 表示验证失败
Validate func(result any) error
// Timeout 步骤级别超时(0 表示使用用例级别超时)
Timeout time.Duration
}
Step 测试步骤
每个步骤包含一个动作和一个验证函数。 动作返回结果后,验证函数检查结果是否符合预期。
type StepResult ¶
type StepResult struct {
// StepName 步骤名称
StepName string
// Passed 是否通过
Passed bool
// Duration 执行耗时
Duration time.Duration
// Error 错误信息(如果失败)
Error string
}
StepResult 步骤执行结果
type SuiteResult ¶
type SuiteResult struct {
// SuiteName 套件名称
SuiteName string
// Results 各用例结果
Results []*TestResult
// TotalCases 用例总数
TotalCases int
// Passed 通过的用例数
Passed int
// Failed 失败的用例数
Failed int
// Duration 总执行耗时
Duration time.Duration
}
SuiteResult 测试套件执行结果
type TestCase ¶
type TestCase struct {
// Name 用例名称
Name string
// Description 用例描述
Description string
// Steps 测试步骤列表,按顺序执行
Steps []Step
// Setup 用例开始前的初始化函数(可选)
Setup func() error
// Teardown 用例结束后的清理函数(可选)
Teardown func() error
// Timeout 用例级别超时(0 表示使用 Runner 默认超时)
Timeout time.Duration
}
TestCase E2E 测试用例
包含一系列测试步骤,按顺序执行。 支持 Setup/Teardown 钩子,分别在用例开始前和结束后调用。
type TestResult ¶
type TestResult struct {
// CaseName 用例名称
CaseName string
// Passed 是否通过
Passed bool
// Steps 各步骤结果
Steps []StepResult
// Duration 总执行耗时
Duration time.Duration
// Error 用例级别的错误信息(例如 Setup 失败)
Error string
}
TestResult 测试用例执行结果
Click to show internal directories.
Click to hide internal directories.