Best Atoum code snippet using runner.addTest
runner.spec.php
Source:runner.spec.php
...13 });14 context("running a single suite", function() {15 it("should run a given suite", function() {16 $suite = new Suite("description", function() {});17 $suite->addTest(new Test("should do a thing", function() {}));18 $suite->addTest(new Test("should fail a thing", function() { throw new \Exception("Fail");}));19 $runner = new Runner($suite, new Configuration(), new EventEmitter());20 $runner->run($this->result);21 assert('2 run, 1 failed' == $this->result->getSummary(), 'result summary should show 2/1');22 });23 });24 context("running a suite with children", function() {25 it("should run a suite with children", function() {26 $parent = new Suite("description 1", function() {});27 $parent->addTest(new Test("should do a thing", function() {}));28 $child = new Suite("description 2", function() {});29 $child->addTest(new Test("should fail a thing", function() { throw new \Exception("Fail");}));30 $grandchild = new Suite("description 3", function() {});31 $grandchild->addTest(new Test("pass a thing", function() { }));32 $parent->addTest($child);33 $child->addTest($grandchild);34 $runner = new Runner($parent, new Configuration(), new EventEmitter());35 $runner->run($this->result);36 assert('3 run, 1 failed' == $this->result->getSummary(), 'result summary should show 3/1');37 });38 });39 describe("->run()", function() {40 beforeEach(function() {41 $this->suite = new Suite("runner test suite", function() {});42 $this->passingTest = new Test("passing spec", function() {});43 $this->failingTest = new Test("failing spec", function() { throw new \Exception("fail"); });44 $this->suite->addTest($this->passingTest);45 $this->suite->addTest($this->failingTest);46 $this->configuration = new Configuration();47 $this->eventEmitter = new EventEmitter();48 $this->runner = new Runner($this->suite, $this->configuration, $this->eventEmitter);49 });50 it('should apply focus patterns if a focus pattern has been set', function() {51 $this->configuration->setFocusPattern('/passing/');52 $count = 0;53 $this->eventEmitter->on('test.start', function() use (&$count) {54 $count++;55 });56 $result = new TestResult($this->eventEmitter);57 $this->runner->run($result);58 assert(1 == $count, 'expected 1 test:start events to fire');59 assert(!$result->isFocusedByDsl(), 'should not be focused by DSL');60 });61 it('should apply focus patterns if a skip pattern has been set', function() {62 $this->configuration->setSkipPattern('/failing/');63 $count = 0;64 $this->eventEmitter->on('test.start', function() use (&$count) {65 $count++;66 });67 $result = new TestResult($this->eventEmitter);68 $this->runner->run($result);69 assert(1 == $count, 'expected 1 test:start events to fire');70 assert(!$result->isFocusedByDsl(), 'should not be focused by DSL');71 });72 it('should apply focus patterns if both focus and skip patterns are set', function() {73 $this->suite->addTest(new Test('another passing spec', function() {}));74 $this->configuration->setFocusPattern('/passing/');75 $this->configuration->setSkipPattern('/another/');76 $count = 0;77 $this->eventEmitter->on('test.start', function() use (&$count) {78 $count++;79 });80 $result = new TestResult($this->eventEmitter);81 $this->runner->run($result);82 assert(1 == $count, 'expected 1 test:start events to fire');83 assert(!$result->isFocusedByDsl(), 'should not be focused by DSL');84 });85 it('should mark the result as focused by DSL where appropriate', function() {86 $this->suite->addTest(new Test('another passing spec', function() {}, true));87 $result = new TestResult($this->eventEmitter);88 $this->runner->run($result);89 assert($result->isFocusedByDsl(), 'should be focused by DSL');90 });91 it("should emit a start event when the runner starts", function() {92 $emitted = false;93 $this->eventEmitter->on('runner.start', function() use (&$emitted) {94 $emitted = true;95 });96 $this->runner->run(new TestResult($this->eventEmitter));97 assert($emitted, 'start event should have been emitted');98 });99 it("should emit an end event with run time and result when the runner ends", function() {100 $time = null;101 $emittedResult = null;102 $this->eventEmitter->on('runner.end', function($timeToRun, $result) use (&$time, &$emittedResult) {103 $time = $timeToRun;104 $emittedResult = $result;105 });106 $result = new TestResult(new EventEmitter());107 $this->runner->run($result);108 assert(is_numeric($time) && $result->getTestCount() > 0, 'end event with a time arg should have been emitted');109 assert($emittedResult === $result, 'end event with a result arg should have been emitted');110 });111 it("should emit a fail event when a spec fails", function() {112 $emitted = null;113 $exception = null;114 $this->eventEmitter->on('test.failed', function($test, $e) use (&$emitted, &$exception) {115 $emitted = $test;116 $exception = $e;117 });118 $this->runner->run(new TestResult($this->eventEmitter));119 assert($emitted === $this->failingTest && !is_null($exception), 'fail event should have been emitted with spec and exception');120 });121 it("should emit a pass event when a spec passes", function() {122 $emitted = null;123 $this->eventEmitter->on('test.passed', function($test) use (&$emitted) {124 $emitted = $test;125 });126 $this->runner->run(new TestResult($this->eventEmitter));127 assert($emitted === $this->passingTest, 'pass event should have been emitted');128 });129 it("should emit a pending event when a spec is pending", function() {130 $emitted = null;131 $this->eventEmitter->on('test.pending', function($test) use (&$emitted) {132 $emitted = $test;133 });134 $this->passingTest->setPending(true);135 $this->runner->run(new TestResult($this->eventEmitter));136 assert($emitted === $this->passingTest, 'pending event should have been emitted');137 });138 it("should emit a suite:start event every time a suite starts", function() {139 $child = new Suite("child suite", function() {});140 $grandchild = new Suite("grandchild suite", function() {});141 $child->addTest($grandchild);142 $this->suite->addTest($child);143 $count = 0;144 $this->eventEmitter->on('suite.start', function() use (&$count) {145 $count++;146 });147 $this->runner->run(new TestResult($this->eventEmitter));148 assert(3 == $count, "expected 3 suite:start events to fire");149 });150 it("should emit a suite:end every time a suite ends", function() {151 $child = new Suite("child suite", function() {});152 $grandchild = new Suite("grandchild suite", function() {});153 $child->addTest($grandchild);154 $this->suite->addTest($child);155 $count = 0;156 $this->eventEmitter->on('suite.end', function() use (&$count) {157 $count++;158 });159 $this->runner->run(new TestResult($this->eventEmitter));160 assert(3 == $count, "expected 3 suite:end events to fire");161 });162 context("when configured to bail on failure", function() {163 it("should stop running on failure", function() {164 $suite = new Suite("suite", function() {});165 $passing = new Test("passing spec", function() {});166 $suite->addTest($passing);167 $childSuite = new Suite("child suite", function() {});168 $passingChild = new Test("passing child", function() {});169 $failingChild = new Test("failing child", function() { throw new Exception("booo"); });170 $passing2Child = new Test("passing2 child", function() {});171 $childSuite->addTest($passingChild);172 $childSuite->addTest($failingChild);173 $childSuite->addTest($passing2Child);174 $suite->addTest($childSuite);175 $passing2 = new Test("passing2 spec", function() {});176 $suite->addTest($passing2);177 $configuration = new Configuration();178 $configuration->stopOnFailure();179 $suite->setEventEmitter($this->eventEmitter);180 $runner = new Runner($suite, $configuration, $this->eventEmitter);181 $result = new TestResult($this->eventEmitter);182 $runner->run($result);183 assert($result->getTestCount() === 3, "spec count should be 3");184 });185 });186 });187});...
AbRunnerTest.php
Source:AbRunnerTest.php
...41 {42 // Arrange43 $phpab = new AbRunner();44 // Act45 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));46 // Assert47 $this->assertCount(1, $phpab->getTests());48 }49 public function testSetTests()50 {51 // Arrange52 $phpab = new AbRunner();53 // Act54 $phpab->setTests(array(55 new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy)56 ));57 // Assert58 $this->assertCount(1, $phpab->getTests());59 }60 public function testSetGetAnalytics()61 {62 // Arrange63 $phpab = new AbRunner();64 $analytics = $this->getMock('PhpAb\Analytics\AnalyticsInterface');65 // Act66 $phpab->setAnalytics($analytics);67 // Assert68 $this->assertEquals($analytics, $phpab->getAnalytics());69 }70 public function testSetGetStorage()71 {72 // Arrange73 $phpab = new AbRunner();74 $storage = $this->getMock('PhpAb\Storage\StorageInterface');75 // Act76 $phpab->setStorage($storage);77 // Assert78 $this->assertEquals($storage, $phpab->getStorage());79 }80 public function testTestWithoutTests()81 {82 // Arrange83 $phpab = new AbRunner();84 // Act85 $executedTests = $phpab->test();86 // Assert87 $this->assertEquals(0, $executedTests);88 }89 public function testTestWithTests()90 {91 // Arrange92 $phpab = new AbRunner();93 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));94 // Act95 $executedTests = $phpab->test();96 // Assert97 $this->assertEquals(1, $executedTests);98 }99 public function testTestWithMultipleTests()100 {101 // Arrange102 $phpab = new AbRunner();103 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));104 $phpab->addTest(new AbTest('test2', $this->callbackA, $this->callbackB, $this->strategy));105 // Act106 $executedTests = $phpab->test();107 // Assert108 $this->assertEquals(2, $executedTests);109 }110 public function testTestWithEmptyStorage()111 {112 // Arrange113 $phpab = new AbRunner();114 $phpab->setStorage($this->getMock('PhpAb\Storage\StorageInterface'));115 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));116 // Act117 $executedTests = $phpab->test();118 // Assert119 $this->assertEquals(1, $executedTests);120 }121 public function testTestWithNonEmptyStorage()122 {123 // Arrange124 $phpab = new AbRunner();125 $phpab->setStorage($this->getMock('PhpAb\Storage\StorageInterface'));126 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));127 // Act128 $executedTests = $phpab->test();129 // Assert130 $this->assertEquals(1, $executedTests);131 }132 public function testTestWithNonParticipatingRunner()133 {134 // Arrange135 $this->strategy->setParticipating(false);136 $phpab = new AbRunner($this->strategy);137 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));138 // Act139 $executedTests = $phpab->test();140 // Assert141 $this->assertEquals(0, $executedTests);142 }143 public function testTestWithNonParticipatingTest()144 {145 // Arrange146 $this->strategy->setParticipating(false);147 $phpab = new AbRunner();148 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));149 // Act150 $executedTests = $phpab->test();151 // Assert152 $this->assertEquals(0, $executedTests);153 }154 public function testTestWithAnalytics()155 {156 // Arrange157 $phpab = new AbRunner();158 $phpab->setAnalytics($this->getMock('PhpAb\Analytics\AnalyticsInterface'));159 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));160 // Act161 $executedTests = $phpab->test();162 // Assert163 $this->assertEquals(1, $executedTests);164 }165 public function testTestWithStorageAndAnalytics()166 {167 // Arrange168 $storage = $this->getMock('PhpAb\Storage\StorageInterface');169 $storage->method('read')->willReturn('B');170 $phpab = new AbRunner();171 $phpab->setAnalytics($this->getMock('PhpAb\Analytics\AnalyticsInterface'));172 $phpab->setStorage($storage);173 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));174 // Act175 $executedTests = $phpab->test();176 // Assert177 $this->assertEquals(1, $executedTests);178 }179 /**180 * @expectedException RuntimeException181 */182 public function testTestWithInvalidStorage()183 {184 // Arrange185 $storage = $this->getMock('PhpAb\Storage\StorageInterface');186 $storage->method('read')->willReturn('ABC');187 $phpab = new AbRunner();188 $phpab->setStorage($storage);189 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, $this->strategy));190 // Act191 $phpab->test();192 // Assert193 // ...194 }195 public function testTestTestWithoutStrategy()196 {197 // Arrange198 $phpab = new AbRunner();199 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, null));200 // Act201 $executedTests = $phpab->test();202 // Assert203 $this->assertEquals(1, $executedTests);204 }205 public function testStrategyFromRunner()206 {207 // Arrange208 $phpab = new AbRunner(new EmptyStrategy(true));209 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, null));210 // Act211 $executedTests = $phpab->test();212 // Assert213 $this->assertEquals(1, $executedTests);214 }215 public function testStrategyFromTest()216 {217 // Arrange218 $phpab = new AbRunner();219 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, new EmptyStrategy(true)));220 // Act221 $executedTests = $phpab->test();222 // Assert223 $this->assertEquals(1, $executedTests);224 }225 public function testStrategyIfNotSetInTest()226 {227 // Arrange228 $phpab = new AbRunner(new EmptyStrategy(false));229 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, null));230 // Act231 $executedTests = $phpab->test();232 // Assert233 $this->assertEquals(0, $executedTests);234 }235 public function testStrategyIfBothSet()236 {237 // Arrange238 $phpab = new AbRunner(new EmptyStrategy(false));239 $phpab->addTest(new AbTest('test', $this->callbackA, $this->callbackB, new EmptyStrategy(true)));240 // Act241 $executedTests = $phpab->test();242 // Assert243 $this->assertEquals(1, $executedTests);244 }245}...
addTest
Using AI Code Generation
1$test = new TestSuite('TestSuite');2$test->addTestFile('2.php');3$test->addTestFile('3.php');4$test->addTestFile('4.php');5$test->run(new HtmlReporter());6$test = new TestSuite('TestSuite');7$test->addTestFile('5.php');8$test->addTestFile('6.php');9$test->addTestFile('7.php');10$test->run(new HtmlReporter());11$test = new TestSuite('TestSuite');12$test->addTestFile('8.php');13$test->addTestFile('9.php');14$test->addTestFile('10.php');15$test->run(new HtmlReporter());16$test = new TestSuite('TestSuite');17$test->addTestFile('11.php');18$test->addTestFile('12.php');19$test->addTestFile('13.php');20$test->run(new HtmlReporter());21$test = new TestSuite('TestSuite');22$test->addTestFile('14.php');23$test->addTestFile('15.php');24$test->addTestFile('16.php');25$test->run(new HtmlReporter());26$test = new TestSuite('TestSuite');27$test->addTestFile('17.php');28$test->addTestFile('18.php');29$test->addTestFile('19.php');30$test->run(new HtmlReporter());31$test = new TestSuite('TestSuite');32$test->addTestFile('20.php');33$test->addTestFile('21.php');34$test->addTestFile('22.php');35$test->run(new HtmlReporter());36$test = new TestSuite('TestSuite');37$test->addTestFile('23.php');38$test->addTestFile('24.php');
addTest
Using AI Code Generation
1require_once 'simpletest/autorun.php';2require_once 'simpletest/web_tester.php';3class TestOfAddition extends WebTestCase {4 function testAddition() {5 $this->assertResponse(200);6 }7}8class TestOfSubtraction extends WebTestCase {9 function testSubtraction() {10 $this->assertResponse(200);11 }12}13class AllTests extends TestSuite {14 function AllTests() {15 $this->TestSuite('All tests');16 $this->addTestFile('1.php');17 $this->addTestFile('2.php');18 }19}20require_once 'simpletest/autorun.php';21require_once 'simpletest/web_tester.php';22class TestOfAddition extends WebTestCase {23 function testAddition() {24 $this->assertResponse(200);25 }26}27class TestOfSubtraction extends WebTestCase {28 function testSubtraction() {29 $this->assertResponse(200);30 }31}32class AllTests extends TestSuite {33 function AllTests() {34 $this->TestSuite('All tests');35 $this->addTestCase(new TestOfAddition());36 $this->addTestCase(new TestOfSubtraction());37 }38}39require_once 'simpletest/autorun.php';40require_once 'simpletest/web_tester.php';41class TestOfAddition extends WebTestCase {42 function testAddition() {43 $this->assertResponse(200);44 }45}46class TestOfSubtraction extends WebTestCase {47 function testSubtraction() {48 $this->assertResponse(200);49 }50}51class AllTests extends TestSuite {52 function AllTests() {53 $this->TestSuite('All tests');54 $this->addTestSuite('TestOfAddition');55 $this->addTestSuite('TestOfSubtraction');56 }57}
addTest
Using AI Code Generation
1$test = new TestSuite();2$test->addTest(new TestOfUnitTestCase());3$test->addTest(new TestOfWebTestCase());4$test->addTest(new TestOfTestSuite());5$test->run(new HtmlReporter());6$test = new TestSuite();7$test->addFile('test1.php');8$test->addFile('test2.php');9$test->addFile('test3.php');10$test->run(new HtmlReporter());11$test = new TestSuite();12$test->addDirectory('test');13$test->run(new HtmlReporter());14$test = new TestSuite();15$test->addTestFile('test/test1.php');16$test->addTestFile('test/test2.php');17$test->addTestFile('test/test3.php');18$test->run(new HtmlReporter());19$test = new TestSuite();20$test->addTestDirectory('test');21$test->run(new HtmlReporter());22$test = new TestSuite();23$test->addTestClass('TestOfUnitTestCase');24$test->addTestClass('TestOfWebTestCase');25$test->addTestClass('TestOfTestSuite');26$test->run(new HtmlReporter());27$test = new TestSuite();28$test->addTestFiles('test/test1.php', 'test/test2.php', 'test/test3.php');29$test->run(new HtmlReporter());30$test = new TestSuite();31$test->addTestDirectories('test', 'test2');32$test->run(new HtmlReporter());33$test = new TestSuite();34$test->addTestClasses('TestOfUnitTestCase', 'TestOfWebTestCase', 'TestOfTestSuite');35$test->run(new HtmlReporter());
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.
Execute automation tests with addTest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!