phpunit 测试

<?php
 
class MyTest
{
 
    public function add($a, $b)
    {
        return $a + $b;
    }

    public function sub($a,$b)
    {
        return $a-$b;
    }
 
}


<?php
require 'mytest.php';
 
use PHPUnitFrameworkTestCase;
 
class MyTestTests extends TestCase
{
    private $mytest;
 
    protected function setUp()
    {
        $this->mytest = new MyTest();
    }
 
    protected function tearDown()
    {
        $this->mytest = NULL;
    }
 
    public function testAdd()
    {
        $result = $this->mytest->add(1, 3);

        $this->assertEquals(4, $result);
    }

    public function testsub(){
        $result = $this->mytest->sub(5, 3);
        $this->assertEquals(2, $result);
    }
 
}

  

原文地址:https://www.cnblogs.com/weixinsb/p/13321305.html