2014-04-15 24 views
9

Tüm verileri için bir API'ye çağrı yapan bir ön uç uygulaması için testler oluşturma ve yazma sürecindeyim. Codeception ile test ediyorum. Şimdiye kadar, işlevsel ve kabul testleri çalışmasına rağmen, API sunumundan bağımsız olarak çalışabilmeleri için işlevsel testlerin API'den bağımsız olmasını istiyorum.codeception - acking çağrı çağrı verileri

API çağrılarından gelen verilerle dalga geçmenin bir yolu var mı? Yoksa bu birim testinin alanı mı?

+0

Bu, muhtemelen bu API çağrılarını yapmak için kullandığınız REST kitaplığına bağlıdır. Aksi takdirde, bir çerçeve ve kütüphane agnostik çözümü, API yanıtlarını bozan ve test ederken gerçek API sunucusu yerine o sunucuyu kullanan hafif bir sunucu işlemi oluşturmak olacaktır. –

+0

[apiary.io] 'ya bir göz atın (http://apiary.io/) Bir API tasarımı ve alayında kullanılabilir – lukasgeiter

cevap

1

API testi için PHPUnit kullandım. Umarım bu sana yardımcı olmuştur.

Bu test için bazı örnek giriş verilerini sağladım ve beklenen hata/başarı kodunu dönme olarak döndüreceğini doğruladım Eğer test beklenen dönüş kodunu almadıysa, bir hata mesajı verecektir. bu sadece farklı test vakalarla bu sınıftaki yeni işlev oluşturmanız gerekir için

class ForgotPasswordTest extends \TestCase{ 

    /** 
    * Test Forgot Password API With valid parameters 
    * It will check forgot password functionality with success conditions 
    */ 

    public function testForgotPasswordWithValidParameter() 
    { 
     $param=array("email"=>"[email protected]"); 
     $response = $this->call('POST', 'forgotPassword',$param); 
     $data = json_decode($response->getContent(), true); 
     if(!isset($data["code"])) 
      $this->assertFalse(false); 
     /** check response code 
     * Return 600 in case if API executed successfully 
     */ 
     $this->assertEquals("600", $data["code"]); 
    } 

    /** 
    * Test Forgot Password API With Invalid parameters 
    * It will check whether you have applied user exist condition 
    */ 

    public function testForgotPasswordWithInValidParameter() 
    { 
     $param=array("email"=>"[email protected]"); 
     $response = $this->call('POST', 'forgotPassword',$param); 
     $data = json_decode($response->getContent(), true); 
     if(!isset($data["code"])) 
      $this->assertFalse(false); 
     /** check response code 
     * Return 404 if user not found 
     */ 
     $this->assertEquals("404", $data["code"]); 
    } 

    /** 
    * Test Forgot Password API With Invalid parameters 
    * It will check input validations are working fine in the API 
    */ 

    public function testForgotPasswordWithInValidEmail() 
    { 
     $param=array("email"=>"satish"); 
     $response = $this->call('POST', 'forgotPassword',$param); 
     $data = json_decode($response->getContent(), true); 
     if(!isset($data["code"])) 
      $this->assertFalse(false); 
     /** check response code 
     * Return 400 error code if there are some input validation error 
     */ 
     $this->assertEquals("400", $data["code"]); 
    } 

} 

Sen, diğer bazı test durumları ayarlayabilirsiniz.