Skip to content

Commit

Permalink
Merge pull request #175 from getgauge/scenario_count
Browse files Browse the repository at this point in the history
add scenario passed/failed/skipped count, getgauge/gauge-vscode#224
  • Loading branch information
sriv committed Apr 11, 2018
2 parents bd3d406 + fda3192 commit aef3d87
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
4 changes: 4 additions & 0 deletions generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type overview struct {
ExecutionTime string
Timestamp string
Summary *summary
ScenarioSummary *summary
BasePath string
PreHookMessages []string
PostHookMessages []string
Expand Down Expand Up @@ -106,6 +107,9 @@ type SuiteResult struct {
PassedSpecsCount int `json:"PassedSpecsCount"`
FailedSpecsCount int `json:"FailedSpecsCount"`
SkippedSpecsCount int `json:"SkippedSpecsCount"`
PassedScenarioCount int `json:"PassedScenarioCount"`
FailedScenarioCount int `json:"FailedScenarioCount"`
SkippedScenarioCount int `json:"SkippedScenarioCount"`
BasePath string `json:"BasePath"`
PreHookMessages []string `json:"PreHookMessages"`
PostHookMessages []string `json:"PostHookMessages"`
Expand Down
10 changes: 5 additions & 5 deletions generator/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,15 @@ var skippedStepRes = &result{

var reportGenTests = []reportGenTest{
{"generate html page start with project name", "htmlPageStartTag", &overview{ProjectName: "projname"}, whtmlPageStartTag},
{"generate report overview with tags", "reportOverviewTag", &overview{"projname", "default", "foo", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, "/", []string{}, []string{}},
{"generate report overview with tags", "reportOverviewTag", &overview{"projname", "default", "foo", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, &summary{41, 2, 39, 0}, "/", []string{}, []string{}},
wChartDiv + wResCntDiv + wEnvLi + wTagsLi + wSuccRateLi + wExecTimeLi + wTimestampLi},
{"generate report overview without tags", "reportOverviewTag", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, "/", []string{}, []string{}},
{"generate report overview without tags", "reportOverviewTag", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, &summary{41, 2, 39, 0}, "/", []string{}, []string{}},
wChartDiv + wResCntDiv + wEnvLi + wSuccRateLi + wExecTimeLi + wTimestampLi},
{"generate suite messages with before hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, "/", []string{"Before Suite message"}, []string{}},
{"generate suite messages with before hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, &summary{41, 2, 39, 0}, "/", []string{"Before Suite message"}, []string{}},
wBeforeSuiteMessageDiv},
{"generate suite messages with after hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, "/", []string{}, []string{"After Suite message"}},
{"generate suite messages with after hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, &summary{41, 2, 39, 0}, "/", []string{}, []string{"After Suite message"}},
wAfterSuiteMessageDiv},
{"generate suite messages with before and after hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, "/", []string{"Before Suite message"}, []string{"After Suite message"}},
{"generate suite messages with before and after hook message", "suiteMessagesDiv", &overview{"projname", "default", "", 34, "00:01:53", "Jun 3, 2016 at 12:29pm", &summary{41, 2, 39, 0}, &summary{41, 2, 39, 0}, "/", []string{"Before Suite message"}, []string{"After Suite message"}},
wBeforeAndAfterSuiteMessageDiv},
{"generate sidebar with appropriate pass/fail/skip class", "sidebarDiv", &sidebar{
IsBeforeHookFailure: false,
Expand Down
15 changes: 15 additions & 0 deletions generator/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func ToSuiteResult(pRoot string, psr *gm.ProtoSuiteResult) *SuiteResult {
suiteResult.SpecResults = make([]*spec, 0)
for _, protoSpecRes := range psr.GetSpecResults() {
suiteResult.SpecResults = append(suiteResult.SpecResults, toSpec(protoSpecRes))
suiteResult.PassedScenarioCount = suiteResult.PassedScenarioCount + int(protoSpecRes.GetScenarioCount()-protoSpecRes.GetScenarioFailedCount()-protoSpecRes.GetScenarioSkippedCount())
suiteResult.FailedScenarioCount = suiteResult.FailedScenarioCount + int(protoSpecRes.GetScenarioFailedCount())
suiteResult.SkippedScenarioCount = suiteResult.SkippedScenarioCount + int(protoSpecRes.GetScenarioSkippedCount())
}
return &suiteResult
}
Expand Down Expand Up @@ -89,6 +92,9 @@ func toNestedSuiteResult(basePath string, result *SuiteResult) *SuiteResult {
sr.PassedSpecsCount++
}
sr.ExecutionTime += spec.ExecutionTime
sr.PassedScenarioCount += spec.PassedScenarioCount
sr.FailedScenarioCount += spec.FailedScenarioCount
sr.SkippedScenarioCount += spec.SkippedScenarioCount
}
sr.SuccessRate = getSuccessRate(len(sr.SpecResults), sr.FailedSpecsCount+sr.SkippedSpecsCount)
return sr
Expand Down Expand Up @@ -117,6 +123,14 @@ func toOverview(res *SuiteResult, filePath string) *overview {
if res.SpecResults != nil {
totalSpecs = len(res.SpecResults)
}

totalScenarios := 0
for _, s := range res.SpecResults {
if s.Scenarios != nil {
totalScenarios = totalScenarios + len(s.Scenarios)
}
}

base := ""
if filePath != "" {
base, _ = filepath.Rel(filepath.Dir(filePath), projectRoot)
Expand All @@ -133,6 +147,7 @@ func toOverview(res *SuiteResult, filePath string) *overview {
ExecutionTime: formatTime(res.ExecutionTime),
Timestamp: res.Timestamp,
Summary: &summary{Failed: res.FailedSpecsCount, Total: totalSpecs, Passed: res.PassedSpecsCount, Skipped: res.SkippedSpecsCount},
ScenarioSummary: &summary{Failed: res.FailedScenarioCount, Total: totalScenarios, Passed: res.PassedScenarioCount, Skipped: res.SkippedScenarioCount},
BasePath: base,
PreHookMessages: res.PreHookMessages,
PostHookMessages: res.PostHookMessages,
Expand Down
63 changes: 51 additions & 12 deletions generator/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,37 @@ var specResWithSpecHookFailure = &gm.ProtoSpecResult{
}

var suiteRes1 = &SuiteResult{
ProjectName: "projName",
Environment: "ci-java",
Tags: "!unimplemented",
SuccessRate: 80,
ExecutionTime: 113163,
Timestamp: "Jun 3, 2016 at 12:29pm",
SpecResults: make([]*spec, 15),
FailedSpecsCount: 2,
SkippedSpecsCount: 5,
PassedSpecsCount: 8,
PreHookMessages: []string{"Before Suite Message"},
PostHookMessages: []string{"After Suite Message"},
ProjectName: "projName",
Environment: "ci-java",
Tags: "!unimplemented",
SuccessRate: 80,
ExecutionTime: 113163,
Timestamp: "Jun 3, 2016 at 12:29pm",
SpecResults: []*spec{
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
&spec{Scenarios: make([]*scenario, 1)},
&spec{Scenarios: make([]*scenario, 2)},
},
PassedScenarioCount: 7,
SkippedScenarioCount: 10,
FailedScenarioCount: 6,
FailedSpecsCount: 2,
SkippedSpecsCount: 5,
PassedSpecsCount: 8,
PreHookMessages: []string{"Before Suite Message"},
PostHookMessages: []string{"After Suite Message"},
}

var scn = &gm.ProtoScenario{
Expand Down Expand Up @@ -490,6 +509,7 @@ func TestToOverview(t *testing.T) {
ExecutionTime: "00:01:53",
Timestamp: "Jun 3, 2016 at 12:29pm",
Summary: &summary{Total: 15, Failed: 2, Passed: 8, Skipped: 5},
ScenarioSummary: &summary{Total: 23, Failed: 6, Passed: 7, Skipped: 10},
PreHookMessages: []string{"Before Suite Message"},
PostHookMessages: []string{"After Suite Message"},
}
Expand Down Expand Up @@ -1426,6 +1446,25 @@ func TestSpecsCountToSuiteResult(t *testing.T) {
}
}

func TestScenarioCountToSuiteResult(t *testing.T) {
psr := &gm.ProtoSuiteResult{SpecResults: []*gm.ProtoSpecResult{
{ScenarioCount: 3, ScenarioFailedCount: 2},
{ScenarioCount: 3, ScenarioSkippedCount: 1},
{ScenarioCount: 3, ScenarioSkippedCount: 1, ScenarioFailedCount: 2},
}}
res := ToSuiteResult("", psr)

if res.PassedScenarioCount != 3 {
t.Errorf("Expected PassedSpecsCount=3; got %d\n", res.PassedScenarioCount)
}
if res.SkippedScenarioCount != 2 {
t.Errorf("Expected SkippedSpecsCount=3; got %d\n", res.SkippedScenarioCount)
}
if res.FailedScenarioCount != 4 {
t.Errorf("Expected FailedSpecsCount=3; got %d\n", res.FailedScenarioCount)
}
}

func TestMapPreHookFailureToSuiteResult(t *testing.T) {
psr := &gm.ProtoSuiteResult{PreHookFailure: &gm.ProtoHookFailure{ErrorMessage: "foo failure"}}
res := ToSuiteResult("", psr)
Expand Down

0 comments on commit aef3d87

Please sign in to comment.