How to use AfterSuiteDidRun method of reporters_test Package

Best Ginkgo code snippet using reporters_test.AfterSuiteDidRun

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

teamcity_reporter_test.go

Source: teamcity_reporter_test.go Github

copy
1package reporters_test
2
3import (
4	"bytes"
5	"fmt"
6	. "github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/ginkgo"
7	"github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/ginkgo/config"
8	"github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/ginkgo/internal/codelocation"
9	"github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/ginkgo/reporters"
10	"github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/ginkgo/types"
11	. "github.com/innotech/hydra-worker-pilot-client/vendors/github.com/onsi/gomega"
12	"time"
13)
14
15var _ = Describe("TeamCity Reporter", func() {
16	var (
17		buffer		bytes.Buffer
18		reporter	Reporter
19	)
20
21	BeforeEach(func() {
22		buffer.Truncate(0)
23		reporter = reporters.NewTeamCityReporter(&buffer)
24		reporter.SpecSuiteWillBegin(config.GinkgoConfigType{}, &types.SuiteSummary{
25			SuiteDescription:		"Foo's test suite",
26			NumberOfSpecsThatWillBeRun:	1,
27		})
28	})
29
30	Describe("a passing test", func() {
31		BeforeEach(func() {
32			beforeSuite := &types.SetupSummary{
33				State: types.SpecStatePassed,
34			}
35			reporter.BeforeSuiteDidRun(beforeSuite)
36
37			afterSuite := &types.SetupSummary{
38				State: types.SpecStatePassed,
39			}
40			reporter.AfterSuiteDidRun(afterSuite)
41
42			spec := &types.SpecSummary{
43				ComponentTexts:	[]string{"[Top Level]", "A", "B", "C"},
44				State:		types.SpecStatePassed,
45				RunTime:	5 * time.Second,
46			}
47			reporter.SpecWillRun(spec)
48			reporter.SpecDidComplete(spec)
49
50			reporter.SpecSuiteDidEnd(&types.SuiteSummary{
51				NumberOfSpecsThatWillBeRun:	1,
52				NumberOfFailedSpecs:		0,
53				RunTime:			10 * time.Second,
54			})
55		})
56
57		It("should record the test as passing", func() {
58			actual := buffer.String()
59			expected :=
60				"##teamcity[testSuiteStarted name='Foo|'s test suite']" +
61					"##teamcity[testStarted name='A B C']" +
62					"##teamcity[testFinished name='A B C' duration='5000']" +
63					"##teamcity[testSuiteFinished name='Foo|'s test suite']"
64			Ω(actual).Should(Equal(expected))
65		})
66	})
67
68	Describe("when the BeforeSuite fails", func() {
69		var beforeSuite *types.SetupSummary
70
71		BeforeEach(func() {
72			beforeSuite = &types.SetupSummary{
73				State:		types.SpecStateFailed,
74				RunTime:	3 * time.Second,
75				Failure: types.SpecFailure{
76					Message:		"failed to setup\n",
77					ComponentCodeLocation:	codelocation.New(0),
78				},
79			}
80			reporter.BeforeSuiteDidRun(beforeSuite)
81
82			reporter.SpecSuiteDidEnd(&types.SuiteSummary{
83				NumberOfSpecsThatWillBeRun:	1,
84				NumberOfFailedSpecs:		1,
85				RunTime:			10 * time.Second,
86			})
87		})
88
89		It("should record the test as having failed", func() {
90			actual := buffer.String()
91			expected := fmt.Sprintf(
92				"##teamcity[testSuiteStarted name='Foo|'s test suite']"+
93					"##teamcity[testStarted name='BeforeSuite']"+
94					"##teamcity[testFailed name='BeforeSuite' message='%s' details='failed to setup|n']"+
95					"##teamcity[testFinished name='BeforeSuite' duration='3000']"+
96					"##teamcity[testSuiteFinished name='Foo|'s test suite']", beforeSuite.Failure.ComponentCodeLocation.String(),
97			)
98			Ω(actual).Should(Equal(expected))
99		})
100	})
101
102	Describe("when the AfterSuite fails", func() {
103		var afterSuite *types.SetupSummary
104
105		BeforeEach(func() {
106			afterSuite = &types.SetupSummary{
107				State:		types.SpecStateFailed,
108				RunTime:	3 * time.Second,
109				Failure: types.SpecFailure{
110					Message:		"failed to setup\n",
111					ComponentCodeLocation:	codelocation.New(0),
112				},
113			}
114			reporter.AfterSuiteDidRun(afterSuite)
115
116			reporter.SpecSuiteDidEnd(&types.SuiteSummary{
117				NumberOfSpecsThatWillBeRun:	1,
118				NumberOfFailedSpecs:		1,
119				RunTime:			10 * time.Second,
120			})
121		})
122
123		It("should record the test as having failed", func() {
124			actual := buffer.String()
125			expected := fmt.Sprintf(
126				"##teamcity[testSuiteStarted name='Foo|'s test suite']"+
127					"##teamcity[testStarted name='AfterSuite']"+
128					"##teamcity[testFailed name='AfterSuite' message='%s' details='failed to setup|n']"+
129					"##teamcity[testFinished name='AfterSuite' duration='3000']"+
130					"##teamcity[testSuiteFinished name='Foo|'s test suite']", afterSuite.Failure.ComponentCodeLocation.String(),
131			)
132			Ω(actual).Should(Equal(expected))
133		})
134	})
135	specStateCases := []struct {
136		state	types.SpecState
137		message	string
138	}{
139		{types.SpecStateFailed, "Failure"},
140		{types.SpecStateTimedOut, "Timeout"},
141		{types.SpecStatePanicked, "Panic"},
142	}
143
144	for _, specStateCase := range specStateCases {
145		specStateCase := specStateCase
146		Describe("a failing test", func() {
147			var spec *types.SpecSummary
148			BeforeEach(func() {
149				spec = &types.SpecSummary{
150					ComponentTexts:	[]string{"[Top Level]", "A", "B", "C"},
151					State:		specStateCase.state,
152					RunTime:	5 * time.Second,
153					Failure: types.SpecFailure{
154						ComponentCodeLocation:	codelocation.New(0),
155						Message:		"I failed",
156					},
157				}
158				reporter.SpecWillRun(spec)
159				reporter.SpecDidComplete(spec)
160
161				reporter.SpecSuiteDidEnd(&types.SuiteSummary{
162					NumberOfSpecsThatWillBeRun:	1,
163					NumberOfFailedSpecs:		1,
164					RunTime:			10 * time.Second,
165				})
166			})
167
168			It("should record test as failing", func() {
169				actual := buffer.String()
170				expected :=
171					fmt.Sprintf("##teamcity[testSuiteStarted name='Foo|'s test suite']"+
172						"##teamcity[testStarted name='A B C']"+
173						"##teamcity[testFailed name='A B C' message='%s' details='I failed']"+
174						"##teamcity[testFinished name='A B C' duration='5000']"+
175						"##teamcity[testSuiteFinished name='Foo|'s test suite']", spec.Failure.ComponentCodeLocation.String())
176				Ω(actual).Should(Equal(expected))
177			})
178		})
179	}
180
181	for _, specStateCase := range []types.SpecState{types.SpecStatePending, types.SpecStateSkipped} {
182		specStateCase := specStateCase
183		Describe("a skipped test", func() {
184			var spec *types.SpecSummary
185			BeforeEach(func() {
186				spec = &types.SpecSummary{
187					ComponentTexts:	[]string{"[Top Level]", "A", "B", "C"},
188					State:		specStateCase,
189					RunTime:	5 * time.Second,
190				}
191				reporter.SpecWillRun(spec)
192				reporter.SpecDidComplete(spec)
193
194				reporter.SpecSuiteDidEnd(&types.SuiteSummary{
195					NumberOfSpecsThatWillBeRun:	1,
196					NumberOfFailedSpecs:		0,
197					RunTime:			10 * time.Second,
198				})
199			})
200
201			It("should record test as ignored", func() {
202				actual := buffer.String()
203				expected :=
204					"##teamcity[testSuiteStarted name='Foo|'s test suite']" +
205						"##teamcity[testStarted name='A B C']" +
206						"##teamcity[testIgnored name='A B C']" +
207						"##teamcity[testFinished name='A B C' duration='5000']" +
208						"##teamcity[testSuiteFinished name='Foo|'s test suite']"
209				Ω(actual).Should(Equal(expected))
210			})
211		})
212	}
213})
214
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger AfterSuiteDidRun code on LambdaTest Cloud Grid

Execute automation tests with AfterSuiteDidRun on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)