-
We have a huge test suit with hundreds of cases, some steps are called more than one time. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think you can try collecting such stats with step/scenario hooks. suite := godog.TestSuite{}
suite.ScenarioInitializer = func(scenarioContext *godog.ScenarioContext) {
// Step definitions ....
type ctxStarted struct{}
scenarioContext.StepContext().Before(func(ctx context.Context, st *godog.Step) (context.Context, error) {
started := time.Now()
return context.WithValue(ctx, ctxStarted{}, started), nil
})
scenarioContext.StepContext().After(func(ctx context.Context, st *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if started, ok := ctx.Value(ctxStarted{}).(time.Time); ok {
time.Since(started)
fmt.Println(st.Text, time.Since(started).String())
}
return ctx, nil
})
} |
Beta Was this translation helpful? Give feedback.
-
It would be interesting to make a formatter that exports result as a trace (to export it in Jaeger for example). Here is an example with opencensus tracer (haven't actually tried if it works 😅 ). suite := godog.TestSuite{}
suite.ScenarioInitializer = func(scenarioContext *godog.ScenarioContext) {
// Step definitions ....
type ctxScenarioSpan struct{}
scenarioContext.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
// "go.opencensus.io/trace"
ctx, span := trace.StartSpan(ctx, sc.Name)
ctx = context.WithValue(ctx, ctxScenarioSpan{}, span)
return ctx, nil
})
scenarioContext.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if span, ok := ctx.Value(ctxScenarioSpan{}).(*trace.Span); ok {
span.End()
}
return ctx, nil
})
type ctxStepSpan struct{}
scenarioContext.StepContext().Before(func(ctx context.Context, st *godog.Step) (context.Context, error) {
ctx, span := trace.StartSpan(ctx, st.Text)
ctx = context.WithValue(ctx, ctxStepSpan{}, span)
return context.WithValue(ctx, ctxStepSpan{}, span), nil
})
scenarioContext.StepContext().After(func(ctx context.Context, st *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if span, ok := ctx.Value(ctxStepSpan{}).(*trace.Span); ok {
span.End()
}
return ctx, nil
})
} |
Beta Was this translation helpful? Give feedback.
I think you can try collecting such stats with step/scenario hooks.