{"id":19279,"date":"2017-03-15T13:11:20","date_gmt":"2017-03-15T13:11:20","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=19279"},"modified":"2024-12-09T17:17:08","modified_gmt":"2024-12-09T17:17:08","slug":"what-is-invocationtimeout-in-testng","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/what-is-invocationtimeout-in-testng\/","title":{"rendered":"What is invocationTimeOut in TestNG?"},"content":{"rendered":"<h2>What is invocationTimeOut in TestNG?<\/h2>\n<p>In this tutorial, let&#8217;s understand <strong>invocationTimeOut<\/strong> test method attribute in TestNG. In TestNG, we can specify the number of times the method can be invoked using the <strong>invocationCount<\/strong> attribute. This attribute is the number of times the test method would be invoked during the run.<\/p>\n<h3>invocationTimeOut<\/h3>\n<p>When we set <strong>invocationCount<\/strong> and <strong>invocationTimeOut<\/strong> on a test method, <strong>invocationTimeOut<\/strong> is the maximum time period TestNG will wait for all the invocations of the test method specified in the attribute <strong>invocationCount<\/strong>.<\/p>\n<p>This attribute specified is in milliseconds of time. For example, to specify 6 secs we have to use<\/p>\n<p>invocationTimeOut=6000<\/p>\n<p>Let&#8217;s see a simple example. The test method executes 5 times.( invocationCount=5)<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19423\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationCount-TestNG.png\" alt=\"invocationCount TestNG\" width=\"1404\" height=\"838\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationCount-TestNG.png 1404w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationCount-TestNG-300x179.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationCount-TestNG-1024x611.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationCount-TestNG-768x458.png 768w\" sizes=\"auto, (max-width: 1404px) 100vw, 1404px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Sample Code Listing<\/h3>\n<pre class=\"dm-pre-admin-side\">package com.testingdocs.testng.tutorials;\r\n\r\nimport org.testng.annotations.Test;\r\n\/\/www.TestingDocs.com - TestNG Tutorials \r\npublic class TestNGInvocationCount {\r\n \r\n\t@Test(invocationCount=5,invocationTimeOut=6000)\r\n\tpublic void sampleTest() throws Exception{\r\n\t\tSystem.out.println(\"Foo.\");\r\n \t\tThread.sleep(1000);\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>Output<\/h3>\n<p>Foo.<br \/>\nFoo.<br \/>\nFoo.<br \/>\nFoo.<br \/>\nFoo.<br \/>\nPASSED: sampleTest<\/p>\n<p>===============================================<br \/>\nDefault test<br \/>\nTests run: 1, Failures: 0, Skips: 0<br \/>\n===============================================<\/p>\n<p>The invocationTimeOut specified in the Test is 6000 ms. The test passed because all the test method invocations executed before the <strong>invocationTimeOut<\/strong>.<\/p>\n<p>The method waits for 1000 ms.<\/p>\n<p><strong>invocationTimeOut<\/strong> &gt; ~ 5 * 1000 ms<\/p>\n<p>Since <strong>6000 &gt; 5*1000 +(small delta ) <\/strong>the test is marked as pass.<\/p>\n<h3>timeOut vs invocationTimeOut<\/h3>\n<p>Test annotation has another attribute called <strong>timeOut<\/strong>. This attribute is the maximum time the method should take to complete. If we mix both the attributes the timeOut will override the <strong>invocationTimeOut<\/strong> value.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"dm-pre-admin-side\">package com.testingdocs.testng.tutorials;\r\n\r\nimport org.testng.annotations.Test;\r\n\r\n\/\/www.TestingDocs.com - TestNG Tutorials \r\n\r\npublic class TestNGInvocationCount {\r\n \r\n\t@Test(invocationCount=5,invocationTimeOut=6000,timeOut=900)\r\n\tpublic void sampleTest() throws Exception{\r\n\t\tSystem.out.println(\"Foo.\");\r\n \t\tThread.sleep(1000);\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19422\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG-.png\" alt=\"invocationTimeOut in TestNG\" width=\"1663\" height=\"780\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG-.png 1663w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG--300x141.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG--1024x480.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG--768x360.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/invocationTimeOut-in-TestNG--1536x720.png 1536w\" sizes=\"auto, (max-width: 1663px) 100vw, 1663px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The test would be marked as failure as the <strong>timeOut<\/strong> attribute overrides the <strong>invocationTimeOut<\/strong> value. i.e When both the values are specified the test run time should be less both the values for the test to be marked as pass.<\/p>\n<p>Test runs that exceed the timeout will fail with the<strong> ThreadTimeoutException:<\/strong><\/p>\n<pre>org.testng.internal.thread.ThreadTimeoutException: Method \r\ncom.testingdocs.testng.tutorials.TestNGInvocationCount.sampleTest() \r\ndidn't finish within the time-out 900<\/pre>\n<p>&nbsp;<\/p>\n<p>TestNG Tutorials on this website can be found at:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.testingdocs.com\/testng-framework-tutorial\/\">https:\/\/www.testingdocs.com\/testng-framework-tutorial\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is invocationTimeOut in TestNG? In this tutorial, let&#8217;s understand invocationTimeOut test method attribute in TestNG. In TestNG, we can specify the number of times the method can be invoked using the invocationCount attribute. This attribute is the number of times the test method would be invoked during the run. invocationTimeOut When we set invocationCount [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[215],"class_list":["post-19279","post","type-post","status-publish","format-standard","hentry","category-testng","tag-testng-questions","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=19279"}],"version-history":[{"count":19,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19279\/revisions"}],"predecessor-version":[{"id":26291,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/19279\/revisions\/26291"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=19279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=19279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=19279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}