{"id":110879,"date":"2018-02-03T14:29:38","date_gmt":"2018-02-03T14:29:38","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=110879"},"modified":"2023-01-04T12:46:59","modified_gmt":"2023-01-04T12:46:59","slug":"perform-unit-testing-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/","title":{"rendered":"Commands to perform unit testing in Magento 2."},"content":{"rendered":"<p>This blog will aware you about the Execution of the unit tests in Magento 2.<br \/>\nBefore proceeding further let&#8217;s get familiar with <a href=\"https:\/\/phpunit.de\/\">PHPUnit<\/a>\u00a0.<br \/>\nHere are few wonderful blog links that can help you understand or have Idea faster.<br \/>\n-&gt;\u00a0<a href=\"https:\/\/webkul.com\/blog\/phpunit-basic-tutorial\/\">https:\/\/webkul.com\/blog\/phpunit-basic-tutorial\/<\/a><br \/>\n-&gt;\u00a0<a href=\"https:\/\/webkul.com\/blog\/writing-tests-for-phpunit\/\">https:\/\/webkul.com\/blog\/writing-tests-for-phpunit\/<\/a><\/p>\n<p>Hope now you have an Idea about the PHPUnit and Unit testing.<\/p>\n<p>Today I am going to share the few commands with which you can execute the Unit Testing.<br \/>\nBut ,<br \/>\nNOTE :\u00a0The <code class=\"highlighter-rouge\">Magento_Developer<\/code> <span class=\"glossary-term\">module<\/span> must be enabled.<br \/>\n1. If you want to Execute all the test cases, then use the below command.<\/p>\n<pre class=\"brush:shell\">php vendor\/bin\/phpunit -c dev\/tests\/unit\/phpunit.xml.dist\n<\/pre>\n<p>OR<\/p>\n<pre class=\"brush:shell\">php bin\/magento dev:tests:run<\/pre>\n<p>NOTE : But the above commands takes too much time.<\/p>\n<p>So We need some thing which is faster , so the solution is to execute the Unit Tests module wise, so below is a command that can help you with.<br \/>\n2. If you want to Execute the Unit tests with specific Module : \u00a0Ex :- magento-catalog .<\/p>\n<pre class=\"brush:shell\">php vendor\/bin\/phpunit -c dev\/tests\/unit\/phpunit.xml.dist vendor\/magento\/module-catalog\/Test\/Unit\/\n<\/pre>\n<p>Magento 2 Uses <strong>PHPUnit<\/strong> Package to run Unit Tests .<br \/>\nBasically PHPUnit automation testing framework has been included as a Dependency in Magento 2\u2019s composer.json file.<\/p>\n<pre class=\"brush:applescript\">    },\n    \"require-dev\": {\n        \"phpunit\/phpunit\": \"~6.2.0\",\n        \"squizlabs\/php_codesniffer\": \"3.1.1\",\n        \"phpmd\/phpmd\": \"@stable\",\n        \"pdepend\/pdepend\": \"2.5.0\",\n        \"friendsofphp\/php-cs-fixer\": \"~2.2.0\",\n        \"lusitanian\/oauth\": \"~0.8.10\",\n        \"sebastian\/phpcpd\": \"2.0.4\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n<\/pre>\n<p><strong>Command Format<\/strong> :<br \/>\n{phpunit_executable} -c {Magentoroot}\/dev\/test\/{type}\/phpunit.xml[.dist] \u00a0path\/to\/module\/test\/dir<\/p>\n<p>This blog is just to have the hands-on Experience to run test of core module.<\/p>\n<p>In Next blog we will learn <a href=\"https:\/\/webkul.com\/blog\/create-custom-module-magento-2-unit-tests\/\">how to create Custom Module&#8217;s unit Test in Magento 2<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog will aware you about the Execution of the unit tests in Magento 2. Before proceeding further let&#8217;s get familiar with PHPUnit\u00a0. Here are few wonderful blog links that can help you understand or have Idea faster. -&gt;\u00a0https:\/\/webkul.com\/blog\/phpunit-basic-tutorial\/ -&gt;\u00a0https:\/\/webkul.com\/blog\/writing-tests-for-phpunit\/ Hope now you have an Idea about the PHPUnit and Unit testing. Today I am <a href=\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":170,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,13],"tags":[6135,2460,1978,6133,6134],"class_list":["post-110879","post","type-post","status-publish","format-standard","hentry","category-magento2","category-php","tag-comands","tag-magento-2","tag-phpunit","tag-unit","tag-unit-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Commands to perform unit testing in Magento 2. - Webkul Blog<\/title>\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\/perform-unit-testing-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Commands to perform unit testing in Magento 2. - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"This blog will aware you about the Execution of the unit tests in Magento 2. Before proceeding further let&#8217;s get familiar with PHPUnit\u00a0. Here are few wonderful blog links that can help you understand or have Idea faster. -&gt;\u00a0https:\/\/webkul.com\/blog\/phpunit-basic-tutorial\/ -&gt;\u00a0https:\/\/webkul.com\/blog\/writing-tests-for-phpunit\/ Hope now you have an Idea about the PHPUnit and Unit testing. Today I am [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\" \/>\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-02-03T14:29:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-04T12:46:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prabhat Rawat\" \/>\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=\"Prabhat Rawat\" \/>\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\/perform-unit-testing-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\"},\"author\":{\"name\":\"Prabhat Rawat\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3d52d6c1ad8a809d2f7548e6a9c3358f\"},\"headline\":\"Commands to perform unit testing in Magento 2.\",\"datePublished\":\"2018-02-03T14:29:38+00:00\",\"dateModified\":\"2023-01-04T12:46:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\"},\"wordCount\":233,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"comands\",\"Magento 2\",\"PHPUnit\",\"Unit\",\"unit testing\"],\"articleSection\":[\"Magento2\",\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\",\"name\":\"Commands to perform unit testing in Magento 2. - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2018-02-03T14:29:38+00:00\",\"dateModified\":\"2023-01-04T12:46:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Commands to perform unit testing in Magento 2.\"}]},{\"@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\/3d52d6c1ad8a809d2f7548e6a9c3358f\",\"name\":\"Prabhat Rawat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?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\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prabhat Rawat\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/prabhat-rawat763\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Commands to perform unit testing in Magento 2. - Webkul Blog","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\/perform-unit-testing-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Commands to perform unit testing in Magento 2. - Webkul Blog","og_description":"This blog will aware you about the Execution of the unit tests in Magento 2. Before proceeding further let&#8217;s get familiar with PHPUnit\u00a0. Here are few wonderful blog links that can help you understand or have Idea faster. -&gt;\u00a0https:\/\/webkul.com\/blog\/phpunit-basic-tutorial\/ -&gt;\u00a0https:\/\/webkul.com\/blog\/writing-tests-for-phpunit\/ Hope now you have an Idea about the PHPUnit and Unit testing. Today I am [...]","og_url":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-02-03T14:29:38+00:00","article_modified_time":"2023-01-04T12:46:59+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Prabhat Rawat","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prabhat Rawat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/"},"author":{"name":"Prabhat Rawat","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3d52d6c1ad8a809d2f7548e6a9c3358f"},"headline":"Commands to perform unit testing in Magento 2.","datePublished":"2018-02-03T14:29:38+00:00","dateModified":"2023-01-04T12:46:59+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/"},"wordCount":233,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["comands","Magento 2","PHPUnit","Unit","unit testing"],"articleSection":["Magento2","php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/","url":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/","name":"Commands to perform unit testing in Magento 2. - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2018-02-03T14:29:38+00:00","dateModified":"2023-01-04T12:46:59+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/perform-unit-testing-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Commands to perform unit testing in Magento 2."}]},{"@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\/3d52d6c1ad8a809d2f7548e6a9c3358f","name":"Prabhat Rawat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?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\/616ec5deaf63b72b3003cf99e608ae354f4d373cee8d25b2d0bfa65cab270ad8?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prabhat Rawat"},"url":"https:\/\/webkul.com\/blog\/author\/prabhat-rawat763\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110879","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\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=110879"}],"version-history":[{"count":8,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110879\/revisions"}],"predecessor-version":[{"id":363121,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/110879\/revisions\/363121"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=110879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=110879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=110879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}