vendredi 4 septembre 2015

how can we do Unit testing of REST API coded using codeigniter?

i have coded few REST API using codeigniter framework for a project,and now i want to write a unit test code for the API using php unit. can anybody provide me a lead to do the same,i am using phpunit for the first time,and have tried to put a simple code.

class ReviewsTest extends PHPUnit_Framework_TestCase { protected $review;

public function setUp()
{
    $this->review = new \application\controllers\api\reviews\get(); 
}

public function testGetMethod()
{
    $response = $this->review->get('/get',['query'=>['product_id'=>'1']]);
    $this->assertEquals(1,$response->getStatusCode());
    $data = $response->json();
     $this->assertArrayHasKey('user_id', $data);
    $this->assertArrayHasKey('rating', $data);

}

}

but when i try to run this file using cmd in windows,no result is displayed. Please try to explain the query with the help of an example.

Aucun commentaire:

Enregistrer un commentaire