2014-04-15 8 views
9

मैं फ्रंट-एंड ऐप के लिए परीक्षण और लेखन के प्रक्रिया में हूं जो अपने सभी डेटा के लिए एपीआई को कॉल कर रहा है। मैं संवेदना के साथ परीक्षण कर रहा हूँ। अभी तक, कार्यात्मक और स्वीकृति परीक्षण हालांकि काम कर रहे हैं, मैं कार्यात्मक परीक्षण एपीआई से स्वतंत्र होना चाहता हूं ताकि मैं एपीआई सेवारत ऐप के आधार पर उन्हें चला सकूं।कोडप्शन - मजेदार एपीआई कॉल डेटा

क्या एपीआई कॉल से आने वाले डेटा का मजाक करने का कोई तरीका है? या यह यूनिट परीक्षण का डोमेन है?

+0

यह शायद उन एपीआई कॉल करने के लिए उपयोग की जाने वाली आरईएसटी लाइब्रेरी पर निर्भर करेगा। अन्यथा एक ढांचा और पुस्तकालय अज्ञेय समाधान एक हल्के सर्वर प्रक्रिया को बनाना होगा जो एपीआई प्रतिक्रियाओं को झुकाएगा और परीक्षण करते समय वास्तविक एपीआई सर्वर के बजाय उस सर्वर का उपयोग करेगा। –

+0

[apiary.io] पर एक नज़र डालें (http://apiary.io/) इसका उपयोग एपीआई को डिजाइन और मॉक करने के लिए किया जा सकता है – lukasgeiter

उत्तर

1

मैंने API परीक्षण के लिए PHPUnit का उपयोग किया है। उम्मीद है इससे आपको मदद मिलेगी।

मैंने अभी इस परीक्षण के लिए कुछ नमूना इनपुट डेटा प्रदान किया है और यह सत्यापित किया है कि यह के रूप में त्रुटि/सफलता कोड लौटाएगा यदि परीक्षण अपेक्षित रिटर्न कोड नहीं मिला है, तो यह एक त्रुटि संकेत देगा।

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"]); 
    } 

} 

आप कुछ अन्य परीक्षण मामलों को भी सेट कर सकते हैं, इसके लिए केवल इस परीक्षा में विभिन्न परीक्षण मामलों के साथ नए कार्य को बनाने की आवश्यकता है।

0

लाइव मॉक HTTP प्रतिक्रियाओं के लिए मॉकी (http://www.mocky.io) देखें जो आप अनुकूलित कर सकते हैं। इसके अलावा, अविश्वसनीय रूप से भयानक जेएसओएन ऑब्जेक्ट्स बनाने के लिए एक शानदार टूल, जेएसओएन जेनरेटर (http://www.json-generator.com/) देखें।

संबंधित मुद्दे