源代码:
1class democontroller extends \think\controller 2{ 3 4/** 5 * @assert (5, 8) == 13 6 * @assert (16, 76) == 92 7 * @assert (6, 16) == 32 8 * @assert (6, 4) == 0 9 * @assert ('abc', 1) == 210 * @param int $a11 * @param int $b12 * @return int13*/14public function plus($a, $b)15 {16return $a + $b;17 }1819/**20 * @assert (14, 8) == 621 * @assert (16, 6) == 1022 * @assert (6, 4) == 023 * @assert ('45', 1) == 4424 * @param int $a25 * @param int $b26 * @return int27*/28public function subtract($a, $b)29 {30return $a - $b;31 }3233public function connecttoserver($servername = null)34 {35if ($servername == null) {36thrownew exception(这不是一个服务器名);37 }38 $fp = fsockopen($servername, 8080);39return ($fp) ? true : false;40 }414243 }
生成测试文件:
1class democontrollertest extends \phpunit_framework_testcase 2{ 3 4/** 5 * @var democontroller 6*/ 7protected $object; 8 9/** 10 * sets up the fixture, for example, opens a network connection. 11 * this method is called before a test is executed. 12*/ 13protected function setup() 14 { 15 $this->object = new democontroller; 16 } 17 18/** 19 * tears down the fixture, for example, closes a network connection. 20 * this method is called after a test is executed. 21*/ 22protected function teardown() 23 { 24 25 } 26 27/** 28 * generated from @assert (5, 8) == 13. 29 * 30 * @covers home\controller\democontroller::plus 31*/ 32public function testplus() 33 { 34 $this->assertequals( 3513, $this->object->plus(5, 8) 36 ); 37 } 38 39/** 40 * generated from @assert (16, 76) == 92. 41 * 42 * @covers home\controller\democontroller::plus 43*/ 44public function testplus2() 45 { 46 $this->assertequals( 4792, $this->object->plus(16, 76) 48 ); 49 } 50 51/** 52 * generated from @assert (6, 16) == 32. 53 * 54 * @covers home\controller\democontroller::plus 55*/ 56public function testplus3() 57 { 58 $this->assertequals( 5932, $this->object->plus(6, 16) 60 ); 61 } 62 63/** 64 * generated from @assert (6, 4) == 0. 65 * 66 * @covers home\controller\democontroller::plus 67*/ 68public function testplus4() 69 { 70 $this->assertequals( 710, $this->object->plus(6, 4) 72 ); 73 } 74 75/** 76 * generated from @assert ('abc', 1) == 0. 77 * 78 * @covers home\controller\democontroller::plus 79*/ 80public function testplus5() 81 { 82 $this->assertequals( 832, $this->object->plus('abc', 1) 84 ); 85 } 86 87/** 88 * generated from @assert (14, 8) == 6. 89 * 90 * @covers home\controller\democontroller::subtract 91*/ 92public function testsubtract() 93 { 94 $this->assertequals( 956, $this->object->subtract(14, 8) 96 ); 97 } 98 99/**100 * generated from @assert (16, 6) == 10.101 *102 * @covers home\controller\democontroller::subtract103*/104public function testsubtract2()105 {106 $this->assertequals(10710, $this->object->subtract(16, 6)108 );109 }110111/**112 * generated from @assert (6, 4) == 0.113 *114 * @covers home\controller\democontroller::subtract115*/116public function testsubtract3()117 {118 $this->assertequals(1190, $this->object->subtract(6, 4)120 );121 }122123/**124 * generated from @assert ('abc', 1) == 0.125 *126 * @covers home\controller\democontroller::subtract127*/128public function testsubtract4()129 {130 $this->assertequals(13144, $this->object->subtract('45', 1)132 );133 }134135/**136 * @covers home\controller\democontroller::connecttoserver137 * @todo implement testconnecttoserver().138*/139public function testconnecttoserver()140 {141//// remove the following lines when you implement this test.142// $this->marktestincomplete(143// 'this test has not been implemented yet.'144// );145 $servername = 'wwwcom';146 $this->asserttrue($this->object->connecttoserver($servername) === false);147 }148public function testconnecttoserver2()149 {150 $servername = 'www.baidu.com';151 $this->asserttrue($this->object->connecttoserver($servername) !== false);152 }
这里的服务器测试用例是手动加上去的!
执行结果:
1 ..fff..f..f 11 / 11 (100%) 2 3 time: 44.42 seconds, memory: 8.75mb 4 5 there were 5 failures: 6 71) home\controller\democontrollertest::testplus3 8 failed asserting that 22 matches expected 32. 910 d:\wamp\www\wxportal\tests\application\home\controller\democontroller.classtest.php:6711122) home\controller\democontrollertest::testplus413 failed asserting that 10 matches expected 0.1415 d:\wamp\www\wxportal\tests\application\home\controller\democontroller.classtest.php:7916173) home\controller\democontrollertest::testplus518 failed asserting that 1 matches expected 2.1920 d:\wamp\www\wxportal\tests\application\home\controller\democontroller.classtest.php:9121224) home\controller\democontrollertest::testsubtract323 failed asserting that 2 matches expected 0.2425 d:\wamp\www\wxportal\tests\application\home\controller\democontroller.classtest.php:12726275) home\controller\democontrollertest::testconnecttoserver228 failed asserting that falseistrue.2930 d:\wamp\www\wxportal\tests\application\home\controller\democontroller.classtest.php:1583132 failures!33 tests: 11, assertions: 11, failures: 5.34 完成。
以上就介绍了2013考研初试时间 phpunit初试,包括了2013考研初试时间方面的内容,希望对php教程有兴趣的朋友有所帮助。
