jeudi 8 septembre 2016

How to unit test the methods of a class whose constructor take some arguments?

I have a class of form something like this:

class A{  
    public function __constructor(Argument 1, Argument 2...){
    //
    }

    public function getSum(var1, var2){
        return var1+var2;
    }
}

My test case class is something like this:

use A;   
class ATest extends PHPUnit_Framework_TestCase{  

    public function testGetSum{  
        $a = new A();
        $this->assertEquals(3, $a->getSum(1,2));  
    }  
}  

However when I run the phpunit, it throws some error like:

Missing argument 1 for \..\::__construct(), called in /../a.php on line 5

Even if I provide the arguments, it throws error.

Is there any other way, I can test the function or something which I am missing.

I don't want to test by using mock (getMockBuilder(),setMethods(),getMock()) as it seems to defy the whole purpose of unit testing.

Aucun commentaire:

Enregistrer un commentaire