{"id":7567,"date":"2013-12-17T13:20:46","date_gmt":"2013-12-17T11:20:46","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=7567"},"modified":"2019-03-21T12:52:47","modified_gmt":"2019-03-21T10:52:47","slug":"junit-time-test-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/","title":{"rendered":"JUnit Time Test Example"},"content":{"rendered":"<p>In this example we are going to see how to use <code>@Test<\/code> annotation along with its optional parameter <code>timeout<\/code> in <a href=\"http:\/\/junit.org\/\">JUnit<\/a> testing framework. Also, we will see how to run our test case from the command line by using the <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/runner\/JUnitCore.html\">org.junit.runner.JUnitCore<\/a><\/code>.<\/p>\n<h2><strong>1. Create the java class to be tested<br \/>\n<\/strong><\/h2>\n<p>Create a folder named <code>JUnitTest<\/code>. This is the folder where your classes will be located. Using a text editor, create a Java class named <code>FirstDayAtSchool.java<\/code>. To make sure your file name is <code>FirstDayAtSchool.java<\/code>, (not <code>FirstDayAtSchool.java.txt<\/code>), first choose <em>&#8220;Save as -&gt; Save as type -&gt; All files&#8221;<\/em>, then type in the file name <code>FirstDayAtSchool.java<\/code>.<\/p>\n<p>&nbsp;<br \/>\n<span style=\"text-decoration: underline;\"><em>FirstDayAtSchool.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">public class FirstDayAtSchool {\n\n\tpublic String[] prepareMyBag() {\n\t\tString[] schoolbag = { \"Books\", \"Notebooks\", \"Pens\" };\n\t\tSystem.out.println(\"Preparing my bag\");\n\t\treturn (schoolbag);\n\t}\n\n\tpublic void printItems(String items) {\n\t\tSystem.out.println(\"My school bag contains: \" + items);\n\t\twhile (true);\n\t}\n}\n<\/pre>\n<h2><strong>2. Create JUnit test case<br \/>\n<\/strong><\/h2>\n<p>In the same directory (<code>JUnitTest<\/code>), use a text editor and create a java class named <code>JunitTest.java<\/code> with the following code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import static org.junit.Assert.assertArrayEquals;\nimport java.util.Arrays;\nimport org.junit.Test;\n\npublic class JunitTest {\n\n   FirstDayAtSchool school = new FirstDayAtSchool();\n   String[] bag = {\"Books\", \"Notebooks\", \"Pens\"};\n  \n   @Test\n   public void testPrepareMyBag() {\t\n      System.out.println(\"Inside testPrepareMyBag()\");    \n      assertArrayEquals(bag, school.prepareMyBag());     \n   }\n\n   @Test(timeout=100)\n   public void testPrintItems() {\t \n      System.out.println(\"Inside printItems()\");   \n      school.printItems(Arrays.toString(bag)); \n   }\n}\n<\/pre>\n<p>Inside the method <code>testPrintItems()<\/code>, we can see that <code>@Test <\/code> annotation is followed by a parameter, called <code>timeout<\/code>. <code>Timeout<\/code> is an optional parameter supported by<code> @Test <\/code>annotation that causes a test to fail if it takes longer than the specified amount of time (measured in milliseconds).<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>For further details regarding the<code> @Test<\/code> annotation, the <code>assertArrayEquals<\/code> assertion (which are also mentioned in our code) and other JUnit Assertions and Annotations, you can have a look at <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-using-assertions-and-annotations-example\/\">JUnit using Assertions and Annotations Example<\/a>.<\/p>\n<h2><strong>3. Run your test case from the command line<br \/>\n<\/strong><\/h2>\n<p>You can run your JUnit test outside Eclipse, by using the <code>org.junit.runner.JUnitCore<\/code> class. This class provides the <code>runClasses()<\/code> method which allows you to execute one or several test classes. The return type of <code>runClasses()<\/code> method is an object of the type <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/runner\/Result.html\">org.junit.runner.Result<\/a><\/code>. This object can be used to collect information about the tests. Also, in case there is a failed test, you can use the object <code><a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/runner\/notification\/Failure.html\">org.junit.runner.notification.Failure<\/a><\/code> which holds description of the failed tests.<\/p>\n<p>The procedure below shows how to run your test outside Eclipse.<\/p>\n<p>In the directory <code>JUnitTest<\/code>, use a text editor and create a new Java class named <code>JunitTestRunner.java<\/code> with the following code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitTestRunner.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import org.junit.runner.JUnitCore;\nimport org.junit.runner.Result;\nimport org.junit.runner.notification.Failure;\n\npublic class JunitTestRunner {\n\n\tpublic static void main(String[] args) {\n\n\t\tResult result = JUnitCore.runClasses(JunitTest.class);\n\t\tfor (Failure fail : result.getFailures()) {\n\t\t\tSystem.out.println(fail.toString());\n\t\t}\n\t\tif (result.wasSuccessful()) {\n\t\t\tSystem.out.println(\"All tests finished successfully...\");\n\t\t}else{\n\t\t\tSystem.out.println(\"The test failed..\");\n\t\t}\n\t}\n}\n<\/pre>\n<ul>\n<li>Open command prompt and move down directories so as to find the directory where your java classes are located:<\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina&gt;cd JUnitTest<\/pre>\n<p><em>Attention: If your classes are located inside a package, for example <code>package com.javacodegeeks.core.junit<\/code>, you can have a look at <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/junit\/junit-ignore-test-example\/\">JUnit Ignore Test Example<\/a>, where we describe exactly what you should do in that case.<\/em>[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<ul>\n<li>When <code>JUnitTest<\/code> is your current directory, compile all the classes in the direcory<\/li>\n<\/ul>\n<p><em>Attention: To run your JUnit tests outside Eclipse properly you need to add the needed JUnit library jars to the classpath of your program. You can find those library jars <a href=\"https:\/\/github.com\/junit-team\/junit\/wiki\/Download-and-Install#plain-old-jar\">here<\/a>.<\/em><\/p>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitTest&gt;javac -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; FirstDayAtSchool.java JunitTest.java JunitTestRunner.java<\/pre>\n<ul>\n<li>Now run the <code>JunitTestRunner<\/code><\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitTest&gt;java -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; JunitTestRunner<\/pre>\n<ul>\n<h3>\n<li>Output:<\/li>\n<\/h3>\n<\/ul>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">Inside testPrepareMyBag()\nPreparing my bag\nInside printItems()\nMy school bag contains: [Books, Notebooks, Pens]\ntestPrintItems(JunitTest): test timed out after 100 milliseconds\nThe test failed..<\/code><\/pre>\n<p>As we see in the output, the first test case testPrepareMyBag() was executed successfully but the second test case testPrintItems() was automatically marked as failed, because its execution took longer than 100 milliseconds, which was the specified number in <code>timeout<\/code> parameter.<\/p>\n<h2>Download the source code<\/h2>\n<p>This was an example of <code>timeout<\/code> parameter, which is supported by <code>@Test<\/code> annotation in JUnit testing framework.<br \/>\nDownload the source code of this example : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/12\/JUnitTest.zip\">JUnitTest.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see how to run our test case from the command line by using the org.junit.runner.JUnitCore. 1. Create the java class to be tested Create a folder named JUnitTest. This &hellip;<\/p>\n","protected":false},"author":9,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-7567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-junit"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit Time Test Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit Time Test Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-12-17T11:20:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-21T10:52:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Konstantina Dimtsa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Konstantina Dimtsa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\"},\"author\":{\"name\":\"Konstantina Dimtsa\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56\"},\"headline\":\"JUnit Time Test Example\",\"datePublished\":\"2013-12-17T11:20:46+00:00\",\"dateModified\":\"2019-03-21T10:52:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\"},\"wordCount\":475,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"articleSection\":[\"junit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\",\"name\":\"JUnit Time Test Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2013-12-17T11:20:46+00:00\",\"dateModified\":\"2019-03-21T10:52:47+00:00\",\"description\":\"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"junit\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JUnit Time Test Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56\",\"name\":\"Konstantina Dimtsa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Konstantina-Dimtsa-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Konstantina-Dimtsa-96x96.jpg\",\"caption\":\"Konstantina Dimtsa\"},\"description\":\"Konstantina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she is currently pursuing M.Sc studies in Advanced Information Systems at the same department. She is also working as a research associate for NKUA in the field of telecommunications. Her main interests lie in software engineering, web applications, databases and telecommunications.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/konstantina-dimtsa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit Time Test Example - Java Code Geeks","description":"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see","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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit Time Test Example - Java Code Geeks","og_description":"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-12-17T11:20:46+00:00","article_modified_time":"2019-03-21T10:52:47+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","type":"image\/jpeg"}],"author":"Konstantina Dimtsa","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Konstantina Dimtsa","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/"},"author":{"name":"Konstantina Dimtsa","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56"},"headline":"JUnit Time Test Example","datePublished":"2013-12-17T11:20:46+00:00","dateModified":"2019-03-21T10:52:47+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/"},"wordCount":475,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","articleSection":["junit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/","name":"JUnit Time Test Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2013-12-17T11:20:46+00:00","dateModified":"2019-03-21T10:52:47+00:00","description":"In this example we are going to see how to use @Test annotation along with its optional parameter timeout in JUnit testing framework. Also, we will see","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-time-test-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"junit","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/junit\/"},{"@type":"ListItem","position":5,"name":"JUnit Time Test Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56","name":"Konstantina Dimtsa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Konstantina-Dimtsa-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Konstantina-Dimtsa-96x96.jpg","caption":"Konstantina Dimtsa"},"description":"Konstantina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she is currently pursuing M.Sc studies in Advanced Information Systems at the same department. She is also working as a research associate for NKUA in the field of telecommunications. Her main interests lie in software engineering, web applications, databases and telecommunications.","sameAs":["http:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/konstantina-dimtsa\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/7567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=7567"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/7567\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/6678"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=7567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=7567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=7567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}