PHPUnit entry case and phpunit entry case. PHPUnit entry case: phpunit entry case: PHPUnit introduction case: PHPUnit this case is about creating a triangle unit test entry case, completed in the netbeans environment. phpunit entry case: PHPUnit entry case
PHPUnit
This case is an entry-level unit test case for creating a triangle. it is completed in the netbeans environment. you can refer to the following materials to build a phpunit in this environment:
Http://www.cnblogs.com/x3d/p/phpunit-in-netbeans8.html
Https://phpunit.de/manual/current/zh_cn/installation.html
Https://github.com/sebastianbergmann/phpunit-skeleton-generator
Original Code class:
InitSide ($ a, $ B, $ c );} /*** initialize the three sides ** @ param int $ a * @ param int $ B * @ param int $ c */protected function initSide (& $ a = 0, & $ B = 0, & $ c = 0) {$ this-> a = intval ($ a); $ this-> B = intval ($ B ); $ this-> c = intval ($ c); return $ this;}/*** construct */public function create ($ a, $ B, $ c) {return $ this-> initSide ($ a, $ B, $ c)-> verifySideIsValid ();}/*** get type */public function getType () {return $ this-> verifyTy Pe ()-> type;}/*** verify that the three sides are valid * @ return boolean */protected function verifySideIsValid () {if (intval ($ this->) <= 0 | intval ($ this-> B) <= 0 | intval ($ this-> c) <= 0) {return false ;} if ($ this-> a + $ this-> B <= $ this-> c) {return false ;} if ($ this-> a + $ this-> c <= $ this-> B) {return false ;} if ($ this-> B + $ this-> c <= $ this-> a) {return false ;} if ($ this-> a-$ this-> B >=$ this-> c) {return fal Se;} if ($ this-> a-$ this-> c >=$ this-> B) {return false ;} if ($ this-> B-$ this-> c >=$ this-> a) {return false;} return true ;} /*** authentication type */protected function verifyType () {if ($ this-> isEquilateral () {$ this-> type = self: TYPE_EQUILATERAL; return $ this;} if ($ this-> isIsosceles () {$ this-> type = self: TYPE_ISOSCELES; return $ this;} $ this-> type = self:: TYPE_ORDINARY; return $ this ;}/*** Whether it is an equi triangle */protected function isEquilateral () {return ($ this-> a = $ this-> B) & ($ this-> B ==$ this-> c ))? True: false;}/*** whether it is an isosceles triangle */protected function isIsosceles () {return ($ this-> a ==$ this-> B) | ($ this-> B ==$ this-> c) | ($ this-> a ==$ this-> c ))? True: false ;}}
Generated test files:
Object = new Triangle;}/*** Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */protected function tearDown () {}/ *** @ dataProvider addDataProvider * @ covers Triangle: create * @ todo Implement testCreate (). */public function testCreate ($ a, $ B, $ c) {// Remove the following lines when you implement this test. /** $ this-> markTestIncomplete ('This test has not been implemented yet. '); ** // * implementation code */$ this-> assertTrue ($ this-> object-> create ($ a, $ B, $ c ));} /*** @ covers Triangle: getType * @ todo Implement testGetType (). */public function testGetType () {// Remove the following lines when you implement this test. $ this-> markTestIncomplete ('This test has not been implemented yet. ');}/*** Test case * @ return array */public function addDataProvider () {return [[3, 4, 5], // yes [2, 2, 2], // yes [8, 10, 8], // yes [2, 3, 4], // yes [1, 2, 3], // no [5, 6, 7], // yes [8, 8, 15], // yes [0, 0, 0], // no [-10, 2, 5], // no [0, 2, 1], // no];}
Note that the test File Class generated after "create/update test" is executed is somewhat different from the above. the test cases here are manually added, for more information, see the instructions in the manual!
Attached execution result:
"/Usr/bin/php" "/usr/local/bin/phpunit" "-- colors" "-- log-junit" "/tmp/nb-phpunit-log.xml" "-- bootstrap ""/ var/www/html/phpunit/test/bootstrap. php ""/usr/local/netbeans-8.1/php/phpunit/NetBeansSuite. php "" -- "" -- run =/var/www/html/phpunit/test/core/triangleTest. php "PHPUnit 5.2.10 by Sebastian Bergmann and contributors ..... F .. FFFI 11/11 (100%) Time: 105 MS, Memory: 10.50 MbThere were 4 failures: 1) Tr IangleTest: testCreate with data set #4 (1, 2, 3) Failed asserting that false is true. /var/www/html/phpunit/test/core/triangleTest. php: 472) TriangleTest: testCreate with data set #7 (0, 0, 0) Failed asserting that false is true. /var/www/html/phpunit/test/core/triangleTest. php: 473) TriangleTest: testCreate with data set #8 (-10, 2, 5) Failed asserting that false is true. /var/www/html/phpunit/test/core /TriangleTest. php: 474) TriangleTest: testCreate with data set #9 (0, 2, 1) Failed asserting that false is true. /var/www/html/phpunit/test/core/triangleTest. php: 47 FAILURES! Tests: 11, Assertions: 10, Failures: 4, Incomplete: 1. complete.
Http://www.bkjia.com/PHPjc/1108859.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1108859.htmlTechArticlePHPUnit entry case, phpunit entry case understanding PHPUnit this case is about creating a triangle unit test entry case, completed in the netbeans environment, about the ride in this environment...