Best Go-testdeep code snippet using test.Helper
fixture_test.go
Source:fixture_test.go
...12}13// -----------------------------------------------------------------------14// Basic fixture ordering verification.15func (s *FixtureS) TestOrder(c *C) {16 helper := FixtureHelper{}17 Run(&helper, nil)18 c.Check(helper.calls[0], Equals, "SetUpSuite")19 c.Check(helper.calls[1], Equals, "SetUpTest")20 c.Check(helper.calls[2], Equals, "Test1")21 c.Check(helper.calls[3], Equals, "TearDownTest")22 c.Check(helper.calls[4], Equals, "SetUpTest")23 c.Check(helper.calls[5], Equals, "Test2")24 c.Check(helper.calls[6], Equals, "TearDownTest")25 c.Check(helper.calls[7], Equals, "TearDownSuite")26 c.Check(len(helper.calls), Equals, 8)27}28// -----------------------------------------------------------------------29// Check the behavior when panics occur within tests and fixtures.30func (s *FixtureS) TestPanicOnTest(c *C) {31 helper := FixtureHelper{panicOn: "Test1"}32 output := String{}33 Run(&helper, &RunConf{Output: &output})34 c.Check(helper.calls[0], Equals, "SetUpSuite")35 c.Check(helper.calls[1], Equals, "SetUpTest")36 c.Check(helper.calls[2], Equals, "Test1")37 c.Check(helper.calls[3], Equals, "TearDownTest")38 c.Check(helper.calls[4], Equals, "SetUpTest")39 c.Check(helper.calls[5], Equals, "Test2")40 c.Check(helper.calls[6], Equals, "TearDownTest")41 c.Check(helper.calls[7], Equals, "TearDownSuite")42 c.Check(len(helper.calls), Equals, 8)43 expected := "^\n-+\n" +44 "PANIC: check_test\\.go:[0-9]+: FixtureHelper.Test1\n\n" +45 "\\.\\.\\. Panic: Test1 \\(PC=[xA-F0-9]+\\)\n\n" +46 ".+:[0-9]+\n" +47 " in (go)?panic\n" +48 ".*check_test.go:[0-9]+\n" +49 " in FixtureHelper.trace\n" +50 ".*check_test.go:[0-9]+\n" +51 " in FixtureHelper.Test1\n" +52 "(.|\n)*$"53 c.Check(output.value, Matches, expected)54}55func (s *FixtureS) TestPanicOnSetUpTest(c *C) {56 helper := FixtureHelper{panicOn: "SetUpTest"}57 output := String{}58 Run(&helper, &RunConf{Output: &output})59 c.Check(helper.calls[0], Equals, "SetUpSuite")60 c.Check(helper.calls[1], Equals, "SetUpTest")61 c.Check(helper.calls[2], Equals, "TearDownTest")62 c.Check(helper.calls[3], Equals, "TearDownSuite")63 c.Check(len(helper.calls), Equals, 4)64 expected := "^\n-+\n" +65 "PANIC: check_test\\.go:[0-9]+: " +66 "FixtureHelper\\.SetUpTest\n\n" +67 "\\.\\.\\. Panic: SetUpTest \\(PC=[xA-F0-9]+\\)\n\n" +68 ".+:[0-9]+\n" +69 " in (go)?panic\n" +70 ".*check_test.go:[0-9]+\n" +71 " in FixtureHelper.trace\n" +72 ".*check_test.go:[0-9]+\n" +73 " in FixtureHelper.SetUpTest\n" +74 "(.|\n)*" +75 "\n-+\n" +76 "PANIC: check_test\\.go:[0-9]+: " +77 "FixtureHelper\\.Test1\n\n" +78 "\\.\\.\\. Panic: Fixture has panicked " +79 "\\(see related PANIC\\)\n$"80 c.Check(output.value, Matches, expected)81}82func (s *FixtureS) TestPanicOnTearDownTest(c *C) {83 helper := FixtureHelper{panicOn: "TearDownTest"}84 output := String{}85 Run(&helper, &RunConf{Output: &output})86 c.Check(helper.calls[0], Equals, "SetUpSuite")87 c.Check(helper.calls[1], Equals, "SetUpTest")88 c.Check(helper.calls[2], Equals, "Test1")89 c.Check(helper.calls[3], Equals, "TearDownTest")90 c.Check(helper.calls[4], Equals, "TearDownSuite")91 c.Check(len(helper.calls), Equals, 5)92 expected := "^\n-+\n" +93 "PANIC: check_test\\.go:[0-9]+: " +94 "FixtureHelper.TearDownTest\n\n" +95 "\\.\\.\\. Panic: TearDownTest \\(PC=[xA-F0-9]+\\)\n\n" +96 ".+:[0-9]+\n" +97 " in (go)?panic\n" +98 ".*check_test.go:[0-9]+\n" +99 " in FixtureHelper.trace\n" +100 ".*check_test.go:[0-9]+\n" +101 " in FixtureHelper.TearDownTest\n" +102 "(.|\n)*" +103 "\n-+\n" +104 "PANIC: check_test\\.go:[0-9]+: " +105 "FixtureHelper\\.Test1\n\n" +106 "\\.\\.\\. Panic: Fixture has panicked " +107 "\\(see related PANIC\\)\n$"108 c.Check(output.value, Matches, expected)109}110func (s *FixtureS) TestPanicOnSetUpSuite(c *C) {111 helper := FixtureHelper{panicOn: "SetUpSuite"}112 output := String{}113 Run(&helper, &RunConf{Output: &output})114 c.Check(helper.calls[0], Equals, "SetUpSuite")115 c.Check(helper.calls[1], Equals, "TearDownSuite")116 c.Check(len(helper.calls), Equals, 2)117 expected := "^\n-+\n" +118 "PANIC: check_test\\.go:[0-9]+: " +119 "FixtureHelper.SetUpSuite\n\n" +120 "\\.\\.\\. Panic: SetUpSuite \\(PC=[xA-F0-9]+\\)\n\n" +121 ".+:[0-9]+\n" +122 " in (go)?panic\n" +123 ".*check_test.go:[0-9]+\n" +124 " in FixtureHelper.trace\n" +125 ".*check_test.go:[0-9]+\n" +126 " in FixtureHelper.SetUpSuite\n" +127 "(.|\n)*$"128 c.Check(output.value, Matches, expected)129}130func (s *FixtureS) TestPanicOnTearDownSuite(c *C) {131 helper := FixtureHelper{panicOn: "TearDownSuite"}132 output := String{}133 Run(&helper, &RunConf{Output: &output})134 c.Check(helper.calls[0], Equals, "SetUpSuite")135 c.Check(helper.calls[1], Equals, "SetUpTest")136 c.Check(helper.calls[2], Equals, "Test1")137 c.Check(helper.calls[3], Equals, "TearDownTest")138 c.Check(helper.calls[4], Equals, "SetUpTest")139 c.Check(helper.calls[5], Equals, "Test2")140 c.Check(helper.calls[6], Equals, "TearDownTest")141 c.Check(helper.calls[7], Equals, "TearDownSuite")142 c.Check(len(helper.calls), Equals, 8)143 expected := "^\n-+\n" +144 "PANIC: check_test\\.go:[0-9]+: " +145 "FixtureHelper.TearDownSuite\n\n" +146 "\\.\\.\\. Panic: TearDownSuite \\(PC=[xA-F0-9]+\\)\n\n" +147 ".+:[0-9]+\n" +148 " in (go)?panic\n" +149 ".*check_test.go:[0-9]+\n" +150 " in FixtureHelper.trace\n" +151 ".*check_test.go:[0-9]+\n" +152 " in FixtureHelper.TearDownSuite\n" +153 "(.|\n)*$"154 c.Check(output.value, Matches, expected)155}156// -----------------------------------------------------------------------157// A wrong argument on a test or fixture will produce a nice error.158func (s *FixtureS) TestPanicOnWrongTestArg(c *C) {159 helper := WrongTestArgHelper{}160 output := String{}161 Run(&helper, &RunConf{Output: &output})162 c.Check(helper.calls[0], Equals, "SetUpSuite")163 c.Check(helper.calls[1], Equals, "SetUpTest")164 c.Check(helper.calls[2], Equals, "TearDownTest")165 c.Check(helper.calls[3], Equals, "SetUpTest")166 c.Check(helper.calls[4], Equals, "Test2")167 c.Check(helper.calls[5], Equals, "TearDownTest")168 c.Check(helper.calls[6], Equals, "TearDownSuite")169 c.Check(len(helper.calls), Equals, 7)170 expected := "^\n-+\n" +171 "PANIC: fixture_test\\.go:[0-9]+: " +172 "WrongTestArgHelper\\.Test1\n\n" +173 "\\.\\.\\. Panic: WrongTestArgHelper\\.Test1 argument " +174 "should be \\*check\\.C\n"175 c.Check(output.value, Matches, expected)176}177func (s *FixtureS) TestPanicOnWrongSetUpTestArg(c *C) {178 helper := WrongSetUpTestArgHelper{}179 output := String{}180 Run(&helper, &RunConf{Output: &output})181 c.Check(len(helper.calls), Equals, 0)182 expected :=183 "^\n-+\n" +184 "PANIC: fixture_test\\.go:[0-9]+: " +185 "WrongSetUpTestArgHelper\\.SetUpTest\n\n" +186 "\\.\\.\\. Panic: WrongSetUpTestArgHelper\\.SetUpTest argument " +187 "should be \\*check\\.C\n"188 c.Check(output.value, Matches, expected)189}190func (s *FixtureS) TestPanicOnWrongSetUpSuiteArg(c *C) {191 helper := WrongSetUpSuiteArgHelper{}192 output := String{}193 Run(&helper, &RunConf{Output: &output})194 c.Check(len(helper.calls), Equals, 0)195 expected :=196 "^\n-+\n" +197 "PANIC: fixture_test\\.go:[0-9]+: " +198 "WrongSetUpSuiteArgHelper\\.SetUpSuite\n\n" +199 "\\.\\.\\. Panic: WrongSetUpSuiteArgHelper\\.SetUpSuite argument " +200 "should be \\*check\\.C\n"201 c.Check(output.value, Matches, expected)202}203// -----------------------------------------------------------------------204// Nice errors also when tests or fixture have wrong arg count.205func (s *FixtureS) TestPanicOnWrongTestArgCount(c *C) {206 helper := WrongTestArgCountHelper{}207 output := String{}208 Run(&helper, &RunConf{Output: &output})209 c.Check(helper.calls[0], Equals, "SetUpSuite")210 c.Check(helper.calls[1], Equals, "SetUpTest")211 c.Check(helper.calls[2], Equals, "TearDownTest")212 c.Check(helper.calls[3], Equals, "SetUpTest")213 c.Check(helper.calls[4], Equals, "Test2")214 c.Check(helper.calls[5], Equals, "TearDownTest")215 c.Check(helper.calls[6], Equals, "TearDownSuite")216 c.Check(len(helper.calls), Equals, 7)217 expected := "^\n-+\n" +218 "PANIC: fixture_test\\.go:[0-9]+: " +219 "WrongTestArgCountHelper\\.Test1\n\n" +220 "\\.\\.\\. Panic: WrongTestArgCountHelper\\.Test1 argument " +221 "should be \\*check\\.C\n"222 c.Check(output.value, Matches, expected)223}224func (s *FixtureS) TestPanicOnWrongSetUpTestArgCount(c *C) {225 helper := WrongSetUpTestArgCountHelper{}226 output := String{}227 Run(&helper, &RunConf{Output: &output})228 c.Check(len(helper.calls), Equals, 0)229 expected :=230 "^\n-+\n" +231 "PANIC: fixture_test\\.go:[0-9]+: " +232 "WrongSetUpTestArgCountHelper\\.SetUpTest\n\n" +233 "\\.\\.\\. Panic: WrongSetUpTestArgCountHelper\\.SetUpTest argument " +234 "should be \\*check\\.C\n"235 c.Check(output.value, Matches, expected)236}237func (s *FixtureS) TestPanicOnWrongSetUpSuiteArgCount(c *C) {238 helper := WrongSetUpSuiteArgCountHelper{}239 output := String{}240 Run(&helper, &RunConf{Output: &output})241 c.Check(len(helper.calls), Equals, 0)242 expected :=243 "^\n-+\n" +244 "PANIC: fixture_test\\.go:[0-9]+: " +245 "WrongSetUpSuiteArgCountHelper\\.SetUpSuite\n\n" +246 "\\.\\.\\. Panic: WrongSetUpSuiteArgCountHelper" +247 "\\.SetUpSuite argument should be \\*check\\.C\n"248 c.Check(output.value, Matches, expected)249}250// -----------------------------------------------------------------------251// Helper test suites with wrong function arguments.252type WrongTestArgHelper struct {253 FixtureHelper254}255func (s *WrongTestArgHelper) Test1(t int) {256}257type WrongSetUpTestArgHelper struct {258 FixtureHelper259}260func (s *WrongSetUpTestArgHelper) SetUpTest(t int) {261}262type WrongSetUpSuiteArgHelper struct {263 FixtureHelper264}265func (s *WrongSetUpSuiteArgHelper) SetUpSuite(t int) {266}267type WrongTestArgCountHelper struct {268 FixtureHelper269}270func (s *WrongTestArgCountHelper) Test1(c *C, i int) {271}272type WrongSetUpTestArgCountHelper struct {273 FixtureHelper274}275func (s *WrongSetUpTestArgCountHelper) SetUpTest(c *C, i int) {276}277type WrongSetUpSuiteArgCountHelper struct {278 FixtureHelper279}280func (s *WrongSetUpSuiteArgCountHelper) SetUpSuite(c *C, i int) {281}282// -----------------------------------------------------------------------283// Ensure fixture doesn't run without tests.284type NoTestsHelper struct {285 hasRun bool286}287func (s *NoTestsHelper) SetUpSuite(c *C) {288 s.hasRun = true289}290func (s *NoTestsHelper) TearDownSuite(c *C) {291 s.hasRun = true292}293func (s *FixtureS) TestFixtureDoesntRunWithoutTests(c *C) {294 helper := NoTestsHelper{}295 output := String{}296 Run(&helper, &RunConf{Output: &output})297 c.Check(helper.hasRun, Equals, false)298}299// -----------------------------------------------------------------------300// Verify that checks and assertions work correctly inside the fixture.301type FixtureCheckHelper struct {302 fail string303 completed bool304}305func (s *FixtureCheckHelper) SetUpSuite(c *C) {306 switch s.fail {307 case "SetUpSuiteAssert":308 c.Assert(false, Equals, true)309 case "SetUpSuiteCheck":310 c.Check(false, Equals, true)311 }312 s.completed = true313}314func (s *FixtureCheckHelper) SetUpTest(c *C) {315 switch s.fail {316 case "SetUpTestAssert":317 c.Assert(false, Equals, true)318 case "SetUpTestCheck":319 c.Check(false, Equals, true)320 }321 s.completed = true322}323func (s *FixtureCheckHelper) Test(c *C) {324 // Do nothing.325}326func (s *FixtureS) TestSetUpSuiteCheck(c *C) {327 helper := FixtureCheckHelper{fail: "SetUpSuiteCheck"}328 output := String{}329 Run(&helper, &RunConf{Output: &output})330 c.Assert(output.value, Matches,331 "\n---+\n"+332 "FAIL: fixture_test\\.go:[0-9]+: "+333 "FixtureCheckHelper\\.SetUpSuite\n\n"+334 "fixture_test\\.go:[0-9]+:\n"+335 " c\\.Check\\(false, Equals, true\\)\n"+336 "\\.+ obtained bool = false\n"+337 "\\.+ expected bool = true\n\n")338 c.Assert(helper.completed, Equals, true)339}340func (s *FixtureS) TestSetUpSuiteAssert(c *C) {341 helper := FixtureCheckHelper{fail: "SetUpSuiteAssert"}342 output := String{}343 Run(&helper, &RunConf{Output: &output})344 c.Assert(output.value, Matches,345 "\n---+\n"+346 "FAIL: fixture_test\\.go:[0-9]+: "+347 "FixtureCheckHelper\\.SetUpSuite\n\n"+348 "fixture_test\\.go:[0-9]+:\n"+349 " c\\.Assert\\(false, Equals, true\\)\n"+350 "\\.+ obtained bool = false\n"+351 "\\.+ expected bool = true\n\n")352 c.Assert(helper.completed, Equals, false)353}354// -----------------------------------------------------------------------355// Verify that logging within SetUpTest() persists within the test log itself.356type FixtureLogHelper struct {357 c *C358}359func (s *FixtureLogHelper) SetUpTest(c *C) {360 s.c = c361 c.Log("1")362}363func (s *FixtureLogHelper) Test(c *C) {364 c.Log("2")365 s.c.Log("3")366 c.Log("4")367 c.Fail()368}369func (s *FixtureLogHelper) TearDownTest(c *C) {370 s.c.Log("5")371}372func (s *FixtureS) TestFixtureLogging(c *C) {373 helper := FixtureLogHelper{}374 output := String{}375 Run(&helper, &RunConf{Output: &output})376 c.Assert(output.value, Matches,377 "\n---+\n"+378 "FAIL: fixture_test\\.go:[0-9]+: "+379 "FixtureLogHelper\\.Test\n\n"+380 "1\n2\n3\n4\n5\n")381}382// -----------------------------------------------------------------------383// Skip() within fixture methods.384func (s *FixtureS) TestSkipSuite(c *C) {385 helper := FixtureHelper{skip: true, skipOnN: 0}386 output := String{}387 result := Run(&helper, &RunConf{Output: &output})388 c.Assert(output.value, Equals, "")389 c.Assert(helper.calls[0], Equals, "SetUpSuite")390 c.Assert(helper.calls[1], Equals, "TearDownSuite")391 c.Assert(len(helper.calls), Equals, 2)392 c.Assert(result.Skipped, Equals, 2)393}394func (s *FixtureS) TestSkipTest(c *C) {395 helper := FixtureHelper{skip: true, skipOnN: 1}396 output := String{}397 result := Run(&helper, &RunConf{Output: &output})398 c.Assert(helper.calls[0], Equals, "SetUpSuite")399 c.Assert(helper.calls[1], Equals, "SetUpTest")400 c.Assert(helper.calls[2], Equals, "SetUpTest")401 c.Assert(helper.calls[3], Equals, "Test2")402 c.Assert(helper.calls[4], Equals, "TearDownTest")403 c.Assert(helper.calls[5], Equals, "TearDownSuite")404 c.Assert(len(helper.calls), Equals, 6)405 c.Assert(result.Skipped, Equals, 1)406}...
run_test.go
Source:run_test.go
...14// -----------------------------------------------------------------------15// Tests ensuring result counting works properly.16func (s *RunS) TestSuccess(c *C) {17 output := String{}18 result := Run(&SuccessHelper{}, &RunConf{Output: &output})19 c.Check(result.Succeeded, Equals, 1)20 c.Check(result.Failed, Equals, 0)21 c.Check(result.Skipped, Equals, 0)22 c.Check(result.Panicked, Equals, 0)23 c.Check(result.FixturePanicked, Equals, 0)24 c.Check(result.Missed, Equals, 0)25 c.Check(result.RunError, IsNil)26}27func (s *RunS) TestFailure(c *C) {28 output := String{}29 result := Run(&FailHelper{}, &RunConf{Output: &output})30 c.Check(result.Succeeded, Equals, 0)31 c.Check(result.Failed, Equals, 1)32 c.Check(result.Skipped, Equals, 0)33 c.Check(result.Panicked, Equals, 0)34 c.Check(result.FixturePanicked, Equals, 0)35 c.Check(result.Missed, Equals, 0)36 c.Check(result.RunError, IsNil)37}38func (s *RunS) TestFixture(c *C) {39 output := String{}40 result := Run(&FixtureHelper{}, &RunConf{Output: &output})41 c.Check(result.Succeeded, Equals, 2)42 c.Check(result.Failed, Equals, 0)43 c.Check(result.Skipped, Equals, 0)44 c.Check(result.Panicked, Equals, 0)45 c.Check(result.FixturePanicked, Equals, 0)46 c.Check(result.Missed, Equals, 0)47 c.Check(result.RunError, IsNil)48}49func (s *RunS) TestPanicOnTest(c *C) {50 output := String{}51 helper := &FixtureHelper{panicOn: "Test1"}52 result := Run(helper, &RunConf{Output: &output})53 c.Check(result.Succeeded, Equals, 1)54 c.Check(result.Failed, Equals, 0)55 c.Check(result.Skipped, Equals, 0)56 c.Check(result.Panicked, Equals, 1)57 c.Check(result.FixturePanicked, Equals, 0)58 c.Check(result.Missed, Equals, 0)59 c.Check(result.RunError, IsNil)60}61func (s *RunS) TestPanicOnSetUpTest(c *C) {62 output := String{}63 helper := &FixtureHelper{panicOn: "SetUpTest"}64 result := Run(helper, &RunConf{Output: &output})65 c.Check(result.Succeeded, Equals, 0)66 c.Check(result.Failed, Equals, 0)67 c.Check(result.Skipped, Equals, 0)68 c.Check(result.Panicked, Equals, 0)69 c.Check(result.FixturePanicked, Equals, 1)70 c.Check(result.Missed, Equals, 2)71 c.Check(result.RunError, IsNil)72}73func (s *RunS) TestPanicOnSetUpSuite(c *C) {74 output := String{}75 helper := &FixtureHelper{panicOn: "SetUpSuite"}76 result := Run(helper, &RunConf{Output: &output})77 c.Check(result.Succeeded, Equals, 0)78 c.Check(result.Failed, Equals, 0)79 c.Check(result.Skipped, Equals, 0)80 c.Check(result.Panicked, Equals, 0)81 c.Check(result.FixturePanicked, Equals, 1)82 c.Check(result.Missed, Equals, 2)83 c.Check(result.RunError, IsNil)84}85// -----------------------------------------------------------------------86// Check result aggregation.87func (s *RunS) TestAdd(c *C) {88 result := &Result{89 Succeeded: 1,90 Skipped: 2,91 Failed: 3,92 Panicked: 4,93 FixturePanicked: 5,94 Missed: 6,95 ExpectedFailures: 7,96 }97 result.Add(&Result{98 Succeeded: 10,99 Skipped: 20,100 Failed: 30,101 Panicked: 40,102 FixturePanicked: 50,103 Missed: 60,104 ExpectedFailures: 70,105 })106 c.Check(result.Succeeded, Equals, 11)107 c.Check(result.Skipped, Equals, 22)108 c.Check(result.Failed, Equals, 33)109 c.Check(result.Panicked, Equals, 44)110 c.Check(result.FixturePanicked, Equals, 55)111 c.Check(result.Missed, Equals, 66)112 c.Check(result.ExpectedFailures, Equals, 77)113 c.Check(result.RunError, IsNil)114}115// -----------------------------------------------------------------------116// Check the Passed() method.117func (s *RunS) TestPassed(c *C) {118 c.Assert((&Result{}).Passed(), Equals, true)119 c.Assert((&Result{Succeeded: 1}).Passed(), Equals, true)120 c.Assert((&Result{Skipped: 1}).Passed(), Equals, true)121 c.Assert((&Result{Failed: 1}).Passed(), Equals, false)122 c.Assert((&Result{Panicked: 1}).Passed(), Equals, false)123 c.Assert((&Result{FixturePanicked: 1}).Passed(), Equals, false)124 c.Assert((&Result{Missed: 1}).Passed(), Equals, false)125 c.Assert((&Result{RunError: errors.New("!")}).Passed(), Equals, false)126}127// -----------------------------------------------------------------------128// Check that result printing is working correctly.129func (s *RunS) TestPrintSuccess(c *C) {130 result := &Result{Succeeded: 5}131 c.Check(result.String(), Equals, "OK: 5 passed")132}133func (s *RunS) TestPrintFailure(c *C) {134 result := &Result{Failed: 5}135 c.Check(result.String(), Equals, "OOPS: 0 passed, 5 FAILED")136}137func (s *RunS) TestPrintSkipped(c *C) {138 result := &Result{Skipped: 5}139 c.Check(result.String(), Equals, "OK: 0 passed, 5 skipped")140}141func (s *RunS) TestPrintExpectedFailures(c *C) {142 result := &Result{ExpectedFailures: 5}143 c.Check(result.String(), Equals, "OK: 0 passed, 5 expected failures")144}145func (s *RunS) TestPrintPanicked(c *C) {146 result := &Result{Panicked: 5}147 c.Check(result.String(), Equals, "OOPS: 0 passed, 5 PANICKED")148}149func (s *RunS) TestPrintFixturePanicked(c *C) {150 result := &Result{FixturePanicked: 5}151 c.Check(result.String(), Equals, "OOPS: 0 passed, 5 FIXTURE-PANICKED")152}153func (s *RunS) TestPrintMissed(c *C) {154 result := &Result{Missed: 5}155 c.Check(result.String(), Equals, "OOPS: 0 passed, 5 MISSED")156}157func (s *RunS) TestPrintAll(c *C) {158 result := &Result{Succeeded: 1, Skipped: 2, ExpectedFailures: 3,159 Panicked: 4, FixturePanicked: 5, Missed: 6}160 c.Check(result.String(), Equals,161 "OOPS: 1 passed, 2 skipped, 3 expected failures, 4 PANICKED, "+162 "5 FIXTURE-PANICKED, 6 MISSED")163}164func (s *RunS) TestPrintRunError(c *C) {165 result := &Result{Succeeded: 1, Failed: 1,166 RunError: errors.New("Kaboom!")}167 c.Check(result.String(), Equals, "ERROR: Kaboom!")168}169// -----------------------------------------------------------------------170// Verify that the method pattern flag works correctly.171func (s *RunS) TestFilterTestName(c *C) {172 helper := FixtureHelper{}173 output := String{}174 runConf := RunConf{Output: &output, Filter: "Test[91]"}175 Run(&helper, &runConf)176 c.Check(helper.calls[0], Equals, "SetUpSuite")177 c.Check(helper.calls[1], Equals, "SetUpTest")178 c.Check(helper.calls[2], Equals, "Test1")179 c.Check(helper.calls[3], Equals, "TearDownTest")180 c.Check(helper.calls[4], Equals, "TearDownSuite")181 c.Check(len(helper.calls), Equals, 5)182}183func (s *RunS) TestFilterTestNameWithAll(c *C) {184 helper := FixtureHelper{}185 output := String{}186 runConf := RunConf{Output: &output, Filter: ".*"}187 Run(&helper, &runConf)188 c.Check(helper.calls[0], Equals, "SetUpSuite")189 c.Check(helper.calls[1], Equals, "SetUpTest")190 c.Check(helper.calls[2], Equals, "Test1")191 c.Check(helper.calls[3], Equals, "TearDownTest")192 c.Check(helper.calls[4], Equals, "SetUpTest")193 c.Check(helper.calls[5], Equals, "Test2")194 c.Check(helper.calls[6], Equals, "TearDownTest")195 c.Check(helper.calls[7], Equals, "TearDownSuite")196 c.Check(len(helper.calls), Equals, 8)197}198func (s *RunS) TestFilterSuiteName(c *C) {199 helper := FixtureHelper{}200 output := String{}201 runConf := RunConf{Output: &output, Filter: "FixtureHelper"}202 Run(&helper, &runConf)203 c.Check(helper.calls[0], Equals, "SetUpSuite")204 c.Check(helper.calls[1], Equals, "SetUpTest")205 c.Check(helper.calls[2], Equals, "Test1")206 c.Check(helper.calls[3], Equals, "TearDownTest")207 c.Check(helper.calls[4], Equals, "SetUpTest")208 c.Check(helper.calls[5], Equals, "Test2")209 c.Check(helper.calls[6], Equals, "TearDownTest")210 c.Check(helper.calls[7], Equals, "TearDownSuite")211 c.Check(len(helper.calls), Equals, 8)212}213func (s *RunS) TestFilterSuiteNameAndTestName(c *C) {214 helper := FixtureHelper{}215 output := String{}216 runConf := RunConf{Output: &output, Filter: "FixtureHelper\\.Test2"}217 Run(&helper, &runConf)218 c.Check(helper.calls[0], Equals, "SetUpSuite")219 c.Check(helper.calls[1], Equals, "SetUpTest")220 c.Check(helper.calls[2], Equals, "Test2")221 c.Check(helper.calls[3], Equals, "TearDownTest")222 c.Check(helper.calls[4], Equals, "TearDownSuite")223 c.Check(len(helper.calls), Equals, 5)224}225func (s *RunS) TestFilterAllOut(c *C) {226 helper := FixtureHelper{}227 output := String{}228 runConf := RunConf{Output: &output, Filter: "NotFound"}229 Run(&helper, &runConf)230 c.Check(len(helper.calls), Equals, 0)231}232func (s *RunS) TestRequirePartialMatch(c *C) {233 helper := FixtureHelper{}234 output := String{}235 runConf := RunConf{Output: &output, Filter: "est"}236 Run(&helper, &runConf)237 c.Check(len(helper.calls), Equals, 8)238}239func (s *RunS) TestFilterError(c *C) {240 helper := FixtureHelper{}241 output := String{}242 runConf := RunConf{Output: &output, Filter: "]["}243 result := Run(&helper, &runConf)244 c.Check(result.String(), Equals,245 "ERROR: Bad filter expression: error parsing regexp: missing closing ]: `[`")246 c.Check(len(helper.calls), Equals, 0)247}248// -----------------------------------------------------------------------249// Verify that List works correctly.250func (s *RunS) TestListFiltered(c *C) {251 names := List(&FixtureHelper{}, &RunConf{Filter: "1"})252 c.Assert(names, DeepEquals, []string{253 "FixtureHelper.Test1",254 })255}256func (s *RunS) TestList(c *C) {257 names := List(&FixtureHelper{}, &RunConf{})258 c.Assert(names, DeepEquals, []string{259 "FixtureHelper.Test1",260 "FixtureHelper.Test2",261 })262}263// -----------------------------------------------------------------------264// Verify that verbose mode prints tests which pass as well.265func (s *RunS) TestVerboseMode(c *C) {266 helper := FixtureHelper{}267 output := String{}268 runConf := RunConf{Output: &output, Verbose: true}269 Run(&helper, &runConf)270 expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t *[.0-9]+s\n" +271 "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t *[.0-9]+s\n"272 c.Assert(output.value, Matches, expected)273}274func (s *RunS) TestVerboseModeWithFailBeforePass(c *C) {275 helper := FixtureHelper{panicOn: "Test1"}276 output := String{}277 runConf := RunConf{Output: &output, Verbose: true}278 Run(&helper, &runConf)279 expected := "(?s).*PANIC.*\n-+\n" + // Should have an extra line.280 "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t *[.0-9]+s\n"281 c.Assert(output.value, Matches, expected)282}283// -----------------------------------------------------------------------284// Verify the stream output mode. In this mode there's no output caching.285type StreamHelper struct {286 l2 sync.Mutex287 l3 sync.Mutex288}289func (s *StreamHelper) SetUpSuite(c *C) {290 c.Log("0")291}292func (s *StreamHelper) Test1(c *C) {293 c.Log("1")294 s.l2.Lock()295 s.l3.Lock()296 go func() {297 s.l2.Lock() // Wait for "2".298 c.Log("3")299 s.l3.Unlock()300 }()301}302func (s *StreamHelper) Test2(c *C) {303 c.Log("2")304 s.l2.Unlock()305 s.l3.Lock() // Wait for "3".306 c.Fail()307 c.Log("4")308}309func (s *RunS) TestStreamMode(c *C) {310 helper := &StreamHelper{}311 output := String{}312 runConf := RunConf{Output: &output, Stream: true}313 Run(helper, &runConf)314 expected := "START: run_test\\.go:[0-9]+: StreamHelper\\.SetUpSuite\n0\n" +315 "PASS: run_test\\.go:[0-9]+: StreamHelper\\.SetUpSuite\t *[.0-9]+s\n\n" +316 "START: run_test\\.go:[0-9]+: StreamHelper\\.Test1\n1\n" +317 "PASS: run_test\\.go:[0-9]+: StreamHelper\\.Test1\t *[.0-9]+s\n\n" +318 "START: run_test\\.go:[0-9]+: StreamHelper\\.Test2\n2\n3\n4\n" +319 "FAIL: run_test\\.go:[0-9]+: StreamHelper\\.Test2\n\n"320 c.Assert(output.value, Matches, expected)321}322type StreamMissHelper struct{}323func (s *StreamMissHelper) SetUpSuite(c *C) {324 c.Log("0")325 c.Fail()326}327func (s *StreamMissHelper) Test1(c *C) {328 c.Log("1")329}330func (s *RunS) TestStreamModeWithMiss(c *C) {331 helper := &StreamMissHelper{}332 output := String{}333 runConf := RunConf{Output: &output, Stream: true}334 Run(helper, &runConf)335 expected := "START: run_test\\.go:[0-9]+: StreamMissHelper\\.SetUpSuite\n0\n" +336 "FAIL: run_test\\.go:[0-9]+: StreamMissHelper\\.SetUpSuite\n\n" +337 "START: run_test\\.go:[0-9]+: StreamMissHelper\\.Test1\n" +338 "MISS: run_test\\.go:[0-9]+: StreamMissHelper\\.Test1\n\n"339 c.Assert(output.value, Matches, expected)340}341// -----------------------------------------------------------------------342// Verify that that the keep work dir request indeed does so.343type WorkDirSuite struct {}344func (s *WorkDirSuite) Test(c *C) {345 c.MkDir()346}347func (s *RunS) TestKeepWorkDir(c *C) {348 output := String{}349 runConf := RunConf{Output: &output, Verbose: true, KeepWorkDir: true}350 result := Run(&WorkDirSuite{}, &runConf)351 c.Assert(result.String(), Matches, ".*\nWORK=" + result.WorkDir)352 stat, err := os.Stat(result.WorkDir)...
Helper
Using AI Code Generation
1import (2func TestMain(m *testing.M) {3 fmt.Println("TestMain")4 m.Run()5}6func TestHelper(t *testing.T) {7 fmt.Println("TestHelper")8 t.Helper()9 t.Log("TestHelper")10}11func TestHelper2(t *testing.T) {12 fmt.Println("TestHelper2")13 t.Log("TestHelper2")14}15func TestHelper3(t *testing.T) {16 fmt.Println("TestHelper3")17 t.Log("TestHelper3")18}
Helper
Using AI Code Generation
1import (2func TestHelper(t *testing.T) {3 t.Helper()4 t.Log("Helper method")5}6import (7func TestSkip(t *testing.T) {8 t.Skip("Skipping the test")9 t.Log("Skip method")10}11import (12func TestSkipNow(t *testing.T) {13 t.SkipNow()14 t.Log("SkipNow method")15}16import (17func TestParallel(t *testing.T) {18 t.Parallel()19 t.Log("Parallel method")20}21import (22func TestRun(t *testing.T) {23 t.Run("Run method", func(t *testing.T) {24 t.Log("Run method")25 })26}27import (28func TestCleanup(t *testing.T) {29 t.Cleanup(func() {30 t.Log("Cleanup method")31 })32}33import (34func TestFatal(t *testing.T) {35 t.Fatal("Fatal method")36 t.Log("Fatal method")37}38import (39func TestFatalf(t *testing.T) {40 t.Fatalf("Fatalf method")41 t.Log("Fatalf method")42}43import (44func TestFailNow(t *testing.T) {45 t.FailNow()46 t.Log("FailNow method")47}48import (49func TestFail(t *testing.T) {50 t.Fail()
Helper
Using AI Code Generation
1func TestHelper(t *testing.T) {2 t.Helper()3 t.Log("Helper method")4}5func TestLog(t *testing.T) {6 t.Log("Log method")7}8func TestError(t *testing.T) {9 t.Error("Error method")10}11func TestFatal(t *testing.T) {12 t.Fatal("Fatal method")13}14func TestFail(t *testing.T) {15 t.Fail()16}17func TestFailNow(t *testing.T) {18 t.FailNow()19}20func TestRun(t *testing.T) {21 t.Run("Run method", func(t *testing.T) {22 t.Log("Run method")23 })24}25func TestSkip(t *testing.T) {26 t.Skip("Skip method")27}28func TestSkipNow(t *testing.T) {29 t.SkipNow()30}31func TestSkipf(t *testing.T) {32 t.Skipf("Skipf method")33}34func TestSkipped(t *testing.T) {35 t.Skipped()36}37func TestParallel(t *testing.T) {38 t.Parallel()39}40func TestCleanup(t *testing.T) {41 t.Cleanup(func() {42 t.Log("Cleanup method")43 })44}45func TestName(t *testing.T) {46 t.Log(t.Name())47}
Helper
Using AI Code Generation
1import (2func TestHelper(t *testing.T) {3 t.Helper()4 fmt.Println("It is a helper method")5}6func TestHelper1(t *testing.T) {7 t.Helper()8 fmt.Println("It is a helper method")9}10func TestHelper2(t *testing.T) {11 t.Helper()12 fmt.Println("It is a helper method")13}14func TestHelper3(t *testing.T) {15 t.Helper()16 fmt.Println("It is a helper method")17}18func TestHelper4(t *testing.T) {19 t.Helper()20 fmt.Println("It is a helper method")21}22func TestHelper5(t *testing.T) {23 t.Helper()24 fmt.Println("It is a helper method")25}26func TestHelper6(t *testing.T) {27 t.Helper()28 fmt.Println("It is a helper method")29}30func TestHelper7(t *testing.T) {31 t.Helper()32 fmt.Println("It is a helper method")33}34func TestHelper8(t *testing.T) {35 t.Helper()36 fmt.Println("It is a helper method")37}38func TestHelper9(t *testing.T) {39 t.Helper()40 fmt.Println("It is a helper method")41}42func TestHelper10(t *testing.T) {43 t.Helper()44 fmt.Println("It is a helper method")45}46func TestHelper11(t *testing.T) {47 t.Helper()48 fmt.Println("It is a helper method")49}50func TestHelper12(t *testing.T) {51 t.Helper()52 fmt.Println("It is a helper method")53}54func TestHelper13(t *testing.T) {55 t.Helper()56 fmt.Println("It is a helper method")57}58func TestHelper14(t *testing.T) {59 t.Helper()60 fmt.Println("It is a helper method")61}62func TestHelper15(t *testing.T) {63 t.Helper()64 fmt.Println("It is a helper method")65}66func TestHelper16(t *testing.T) {67 t.Helper()68 fmt.Println("It is a helper method")69}70func TestHelper17(t *testing.T) {71 t.Helper()72 fmt.Println("It is a helper method")73}74func TestHelper18(t *testing.T) {75 t.Helper()76 fmt.Println("It is a helper method")77}78func TestHelper19(t *testing.T) {
Helper
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 test.Helper()5}6import (7func main() {8 fmt.Println("Hello World")9 test.Helper()10}11import (12func main() {13 fmt.Println("Hello World")14 test.Helper()15}16import (17func main() {18 fmt.Println("Hello World")19 test.Helper()20}21import (22func main() {23 fmt.Println("Hello World")24 test.Helper()25}26import (27func main() {28 fmt.Println("Hello World")29 test.Helper()30}31import (32func main() {33 fmt.Println("Hello World")34 test.Helper()35}36import (37func main() {38 fmt.Println("Hello World")39 test.Helper()40}41import (42func main() {43 fmt.Println("Hello World")44 test.Helper()45}46import (47func main() {48 fmt.Println("Hello World")49 test.Helper()50}51import (52func main() {53 fmt.Println("Hello World")54 test.Helper()55}56import
Helper
Using AI Code Generation
1public class TestClass {2 public static void main(String[] args) {3 TestClass test = new TestClass();4 test.helper();5 }6 public void helper() {7 System.out.println("Hello World");8 }9}10public class Main {11 public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {12 Class<?> testClass = Class.forName("TestClass");13 Method helper = testClass.getMethod("helper");14 helper.invoke(testClass);15 }16}
Helper
Using AI Code Generation
1import (2func TestMain(t *testing.T) {3 fmt.Println("TestMain")4 t.Helper()5 t.Error("Error")6}7import (8func TestMain(t *testing.T) {9 fmt.Println("TestMain")10 t.Helper()11 t.Fatal("Fatal")12}13import (14func TestMain(t *testing.T) {15 fmt.Println("TestMain")16 t.Helper()17 t.Skip("Skip")18}19import (20func TestMain(t *testing.T) {21 fmt.Println("TestMain")22 t.Helper()23 t.SkipNow()24}25import (26func TestMain(t *testing.T) {27 fmt.Println("TestMain")28 t.Helper()29 t.Skipf("Skipf")30}31import (32func TestMain(t *testing.T) {33 fmt.Println("TestMain")34 t.Helper()35 t.Log("Log")36}37import (38func TestMain(t *testing.T) {39 fmt.Println("TestMain")40 t.Helper()41 t.Logf("Logf")42}43import (44func TestMain(t *testing.T) {45 fmt.Println("TestMain")46 t.Helper()47 t.Parallel()48}49import (50func TestMain(t *testing.T) {51 fmt.Println("TestMain")
Helper
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World!")4 test.HelperMethod()5}6func HelperMethod() {7 println("This is HelperMethod")8}9func HelperMethod() {10 println("This is HelperMethod")11}12 /usr/local/go/src/test (from $GOROOT)13 /home/user/go/src/test (from $GOPATH)14 /home/user/go/src/test (from $GOPATH)15./test.go:5:8: local import "./test" in non-local package16./test.go:5:8: local import "./test" in non-local package17./test.go:5:8: local import "./test" in non-local package
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!