{"id":107998,"date":"2018-01-06T16:21:40","date_gmt":"2018-01-06T16:21:40","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=107998"},"modified":"2018-01-06T16:21:40","modified_gmt":"2018-01-06T16:21:40","slug":"unit-testing-magento","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/unit-testing-magento\/","title":{"rendered":"Unit testing in magento 1"},"content":{"rendered":"<p>Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.<\/p>\n<h3>Setup<\/h3>\n<p>Go to your root parallel to your &#8216;<em>app<\/em>&#8216; folder from your terminal and paste the following command-<\/p>\n<p><em>composer require phpunit\/phpunit<\/em><\/p>\n<p>This will install PHPUnit in your server<\/p>\n<p><img decoding=\"async\" class=\"wp-image-107999 size-full\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\" alt=\"unit testing\" width=\"936\" height=\"688\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png 936w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377-250x184.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377-300x221.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377-768x565.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" loading=\"lazy\" \/><\/p>\n<p>Our setup is completed.<\/p>\n<h3>Implementation<\/h3>\n<p>Create a xml file phpunit.xml parallel to your app folder and write the following code there.<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;phpunit bootstrap=\"vendor\/autoload.php\"\r\n        colors=\"true\"\r\n        verbose=\"true\"\r\n        stopOnFailure=\"false\"&gt;\r\n    &lt;testsuites&gt;\r\n        &lt;testsuite name=\"My Test Suite\"&gt;\r\n            &lt;directory&gt;tests&lt;\/directory&gt;\r\n        &lt;\/testsuite&gt;\r\n    &lt;\/testsuites&gt;\r\n&lt;\/phpunit&gt;<\/pre>\n<p>Inside <em>&lt;directory&gt;<\/em>\u00a0the path to the test files is mentioned. Now create a folder named &#8216;<em>tests<\/em>&#8216; as mentioned in the xml file parallel to app folder. Inside the <em>tests\u00a0<\/em>folder create a PHP file Test.php (any name)<\/p>\n<p>In the Test.php file write the following code.<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nrequire_once '.\/app\/Mage.php';\r\nrequire_once '.\/app\/code\/local\/Webkul\/Module\/Helper\/Data.php';\r\nclass Test extends \\PHPUnit\\Framework\\TestCase {\r\n\r\n    \/** @test *\/\r\n    public function test_function() {\r\n        $data = new Webkul_Module_Helper_Data();\r\n\r\n        $this-&gt;assertEquals($data-&gt;getTotal(200),200);\r\n\r\n    }\r\n\r\n}<\/pre>\n<p><i>assertEquals\u00a0<\/i>checks if the two parameters are equal or not. Here we are calling a function getTotal() in Data.php file inside Helper. If that function returns value 200 then we will see the following output<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-108000 size-full\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_378.png\" alt=\"output\" width=\"817\" height=\"211\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_378.png 817w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_378-250x65.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_378-300x77.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_378-768x198.png 768w\" sizes=\"(max-width: 817px) 100vw, 817px\" loading=\"lazy\" \/><\/p>\n<p>Use this code in terminal to check output<\/p>\n<p><em>.\/vendor\/bin\/phpunit<\/em><\/p>\n<p>Hope this helps. Happy Coding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1. Setup Go to your root parallel to your &#8216;app&#8216; folder from your terminal and paste the following command- composer require phpunit\/phpunit This will install PHPUnit <a href=\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":164,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-107998","post","type-post","status-publish","format-standard","hentry","category-magento"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unit testing in magento 1 - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unit testing in magento 1 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-06T16:21:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\" \/>\n<meta name=\"author\" content=\"Paul Dutta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Dutta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\"},\"author\":{\"name\":\"Paul Dutta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/41a945ef9d13b037b8483b2340ae6748\"},\"headline\":\"Unit testing in magento 1\",\"datePublished\":\"2018-01-06T16:21:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\"},\"wordCount\":184,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\",\"articleSection\":[\"magento\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\",\"url\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\",\"name\":\"Unit testing in magento 1 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\",\"datePublished\":\"2018-01-06T16:21:40+00:00\",\"description\":\"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/unit-testing-magento\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png\",\"width\":936,\"height\":688},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/unit-testing-magento\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unit testing in magento 1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/41a945ef9d13b037b8483b2340ae6748\",\"name\":\"Paul Dutta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/57d5fe0b5f0a7db7ce6bf447f403ff0c10c3d2e234e4a8398a8fe1daa71888b2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/57d5fe0b5f0a7db7ce6bf447f403ff0c10c3d2e234e4a8398a8fe1daa71888b2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Paul Dutta\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/paul-dutta287\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unit testing in magento 1 - Webkul Blog","description":"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/unit-testing-magento\/","og_locale":"en_US","og_type":"article","og_title":"Unit testing in magento 1 - Webkul Blog","og_description":"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.","og_url":"https:\/\/webkul.com\/blog\/unit-testing-magento\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-01-06T16:21:40+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png","type":"","width":"","height":""}],"author":"Paul Dutta","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Paul Dutta","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/"},"author":{"name":"Paul Dutta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/41a945ef9d13b037b8483b2340ae6748"},"headline":"Unit testing in magento 1","datePublished":"2018-01-06T16:21:40+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/"},"wordCount":184,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png","articleSection":["magento"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/unit-testing-magento\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/","url":"https:\/\/webkul.com\/blog\/unit-testing-magento\/","name":"Unit testing in magento 1 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png","datePublished":"2018-01-06T16:21:40+00:00","description":"Developers who follows best practices of coding write unit testing in their extensions. We will see the basics of how to setup and use PHP unit testing in magento 1.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/unit-testing-magento\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2018\/01\/Screenshot_377.png","width":936,"height":688},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/unit-testing-magento\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Unit testing in magento 1"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/41a945ef9d13b037b8483b2340ae6748","name":"Paul Dutta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/57d5fe0b5f0a7db7ce6bf447f403ff0c10c3d2e234e4a8398a8fe1daa71888b2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/57d5fe0b5f0a7db7ce6bf447f403ff0c10c3d2e234e4a8398a8fe1daa71888b2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Paul Dutta"},"url":"https:\/\/webkul.com\/blog\/author\/paul-dutta287\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/164"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=107998"}],"version-history":[{"count":2,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107998\/revisions"}],"predecessor-version":[{"id":108002,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107998\/revisions\/108002"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=107998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=107998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=107998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}