PHP simpleTest 单元测试

WBOY
Release: 2016-06-23 14:30:36
Original
1223 people have browsed it

   simpleTest  UnitTest  一直听说有这些东西可惜重来没时间研究(借口)。 今天得闲 研究了一下,算是给和我一样第一次用的朋友一点启示吧

  直接上码:

  

<?phprequire_once('simpletest/autorun.php');class test {   public function testfun($a,$b){      return $a+$b;   }}// 从UnitTestCase类继class  myFirstUnitTest extends UnitTestCase {     function BaicUnitTest($name = '') {        $this->UnitTestCase($name); // $name作为测试页的heading显示}         function testEqual() {        $testIns = new test();        $this->assertEqual(25, $testIns->testfun(10, 15));}}$test = new BasicUnitTest();$test->run(new HtmlReporter());?>
Copy after login

页面显示 :

没什么技术含量  这里只是简单测试了下测试类返回的方法是否等于期望值

测试其他情况时候可以把    $this->assertEqual(25, $testIns->testfun(10, 15)); assertEqual 替换成其他 具体见----官方手册 这里只是抛砖- -

上面的class 可以换成include_once('需要测试的类.class.php');

官方上规范的说是把每个测试文件都放到一个test 文件夹下便于后期维护

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!