{"id":311333,"date":"2021-11-11T09:02:15","date_gmt":"2021-11-11T09:02:15","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=311333"},"modified":"2023-05-08T15:05:28","modified_gmt":"2023-05-08T15:05:28","slug":"running-unit-tests-in-magento2-using-cli-command","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/","title":{"rendered":"Running Unit Tests in Magento2 using CLI command"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Running all unit tests<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to your Magento root directory.<\/li>\n\n\n\n<li>Run the below command, where <code>c<\/code> option specifies the path to the <code>phpunit<\/code> configuration file <\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\">.\/vendor\/bin\/phpunit -c dev\/tests\/unit\/phpunit.xml.dist<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Running only a subset of the unit tests<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For running unit tests only for a single module use the below command.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\">.\/vendor\/bin\/phpunit -c dev\/tests\/unit\/phpunit.xml.dist app\/code\/Example\/Module\/Test\/Unit<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need to specify your module directory as shown in the above code snippet.<\/li>\n\n\n\n<li>After that, the <code>phpunit<\/code> will scan the directory for files ending with <code>Test.php<\/code> and try to execute them.<\/li>\n<\/ul>\n\n\n\n<p>You can visit the following blog for creating the unit test.<\/p>\n\n\n<a class=\"wp-block-read-more\" href=\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\" target=\"_self\">https:\/\/webkul.com\/blog\/php-unit-test-in-magento-open-source\/<span class=\"screen-reader-text\">: Running Unit Tests in Magento2 using CLI command<\/span><\/a>","protected":false},"excerpt":{"rendered":"<p>Running all unit tests Running only a subset of the unit tests You can visit the following blog for creating the unit test.<\/p>\n","protected":false},"author":370,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-311333","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Running Unit Tests in Magento2 using CLI command<\/title>\n<meta name=\"description\" content=\"Learn how to run unit tests in Magento 2 using CLI command.\" \/>\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\/running-unit-tests-in-magento2-using-cli-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running Unit Tests in Magento2 using CLI command\" \/>\n<meta property=\"og:description\" content=\"Learn how to run unit tests in Magento 2 using CLI command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\" \/>\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=\"2021-11-11T09:02:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-08T15:05:28+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=\"Piyush Goel\" \/>\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=\"Piyush Goel\" \/>\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\/running-unit-tests-in-magento2-using-cli-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\"},\"author\":{\"name\":\"Piyush Goel\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/b7e57903873f644e164ab966ddc2dfaa\"},\"headline\":\"Running Unit Tests in Magento2 using CLI command\",\"datePublished\":\"2021-11-11T09:02:15+00:00\",\"dateModified\":\"2023-05-08T15:05:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\"},\"wordCount\":93,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\",\"url\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\",\"name\":\"Running Unit Tests in Magento2 using CLI command\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2021-11-11T09:02:15+00:00\",\"dateModified\":\"2023-05-08T15:05:28+00:00\",\"description\":\"Learn how to run unit tests in Magento 2 using CLI command.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running Unit Tests in Magento2 using CLI command\"}]},{\"@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\/b7e57903873f644e164ab966ddc2dfaa\",\"name\":\"Piyush Goel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9ac760cf4b3f2187249f6510acc102cdb51926a23b59b9926232575f2316be6a?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\/9ac760cf4b3f2187249f6510acc102cdb51926a23b59b9926232575f2316be6a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Piyush Goel\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/piyush-goel190\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running Unit Tests in Magento2 using CLI command","description":"Learn how to run unit tests in Magento 2 using CLI command.","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\/running-unit-tests-in-magento2-using-cli-command\/","og_locale":"en_US","og_type":"article","og_title":"Running Unit Tests in Magento2 using CLI command","og_description":"Learn how to run unit tests in Magento 2 using CLI command.","og_url":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-11-11T09:02:15+00:00","article_modified_time":"2023-05-08T15:05:28+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":"Piyush Goel","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Piyush Goel","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/"},"author":{"name":"Piyush Goel","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/b7e57903873f644e164ab966ddc2dfaa"},"headline":"Running Unit Tests in Magento2 using CLI command","datePublished":"2021-11-11T09:02:15+00:00","dateModified":"2023-05-08T15:05:28+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/"},"wordCount":93,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/","url":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/","name":"Running Unit Tests in Magento2 using CLI command","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2021-11-11T09:02:15+00:00","dateModified":"2023-05-08T15:05:28+00:00","description":"Learn how to run unit tests in Magento 2 using CLI command.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/running-unit-tests-in-magento2-using-cli-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Running Unit Tests in Magento2 using CLI command"}]},{"@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\/b7e57903873f644e164ab966ddc2dfaa","name":"Piyush Goel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9ac760cf4b3f2187249f6510acc102cdb51926a23b59b9926232575f2316be6a?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\/9ac760cf4b3f2187249f6510acc102cdb51926a23b59b9926232575f2316be6a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Piyush Goel"},"url":"https:\/\/webkul.com\/blog\/author\/piyush-goel190\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/311333","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\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=311333"}],"version-history":[{"count":5,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/311333\/revisions"}],"predecessor-version":[{"id":380383,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/311333\/revisions\/380383"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=311333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=311333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=311333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}