{"id":7582,"date":"2013-12-19T12:14:19","date_gmt":"2013-12-19T10:14:19","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=7582"},"modified":"2019-03-21T12:52:19","modified_gmt":"2019-03-21T10:52:19","slug":"junit-exceptions-test-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/","title":{"rendered":"JUnit Exceptions 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><strong>expected<\/strong><\/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>JUnitExceptions<\/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\">import java.util.Arrays;\n\npublic class FirstDayAtSchool {\n\n\tpublic String[] prepareMyBag() {\n\t\tString[] schoolbag = { \"Books\", \"Notebooks\", \"Pens\" };\n\t\tSystem.out.println(\"I put in my bag: \"+Arrays.toString(schoolbag));\n\t\treturn (schoolbag);\n\t}\n\n\tpublic void printItems(String []items) {\n\t\t\n\t\tSystem.out.println(\"The last item I put in my bag was: \" +items[items.length]);\n\t\t\n\t}\n}\n<\/pre>\n<h2><strong>2. Create JUnit test case<br \/>\n<\/strong><\/h2>\n<p>In the same directory (<code>JUnitExceptions<\/code>), use a text editor and create a java class named <code>JunitExceptionsTest1.java<\/code> with the following code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitExceptionsTest1.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import static org.junit.Assert.assertArrayEquals;\nimport org.junit.Test;\n\npublic class JunitExceptionsTest1 {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\tString[] bag = { \"Books\", \"Notebooks\", \"Pens\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag, school.prepareMyBag());\n\t}\n\n\t@Test(expected = ArrayIndexOutOfBoundsException.class)\n\tpublic void testPrintItems() {\n\t\tSystem.out.println(\"Inside printItems()\");\n\t\tschool.printItems(bag);\n\t}\n}\n<\/pre>\n<p>In the same way, create another class named <code>JunitExceptionsTest2.java<\/code> with similar code, where the only difference with the previous class will be the declared exception.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitExceptionsTest2.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import static org.junit.Assert.assertArrayEquals;\nimport org.junit.Test;\n\npublic class JunitExceptionsTest2 {\n\n\tFirstDayAtSchool school = new FirstDayAtSchool();\n\tString[] bag = { \"Books\", \"Notebooks\", \"Pens\" };\n\n\t@Test\n\tpublic void testPrepareMyBag() {\n\t\tSystem.out.println(\"Inside testPrepareMyBag()\");\n\t\tassertArrayEquals(bag, school.prepareMyBag());\n\t}\n\n\t@Test(expected = ArithmeticException.class)\n\tpublic void testPrintItems() {\n\t\tSystem.out.println(\"Inside printItems()\");\n\t\tschool.printItems(bag);\n\t}\n}\n<\/pre>\n<p>In the method <code>testPrintItems()<\/code> in both java classes, we can see that <code>@Test <\/code> annotation is followed by a parameter, called <code>expected<\/code>. The <code>expected<\/code> is an optional parameter supported by<code> @Test <\/code>annotation which declares that a test method should throw an exception. If it doesn&#8217;t throw an exception or if it throws a different exception than the one declared, the test fails, otherwise it succeeds.<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 cases 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>JUnitExceptions<\/code>, use a text editor and create a new Java class named <code>JunitExceptionsTestRunner.java<\/code> with the following code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitExceptionsTestRunner.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 JunitExceptionsTestRunner {\n\n\tpublic static void main(String[] args) {\n\n\t\tResult result = JUnitCore.runClasses(JunitExceptionsTest1.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}\n\t}\n}\n<\/pre>\n<p>We will first run the <code>JunitExceptions1.java,<\/code> so the argument of <code>runClasses<\/code> method will be the perspective class.<\/p>\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 JUnitExceptions<\/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><\/p>\n<ul>\n<li>When <code>JUnitExceptions<\/code> is your current directory, compile all the classes in the directory<\/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>[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitExceptions&gt;javac -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; FirstDayAtSchool.java JunitExceptionsTest1.java JunitExceptionsTest2.java JunitExceptionsTestRunner.java<\/pre>\n<ul>\n<li>Now run the <code>JunitExceptionsTestRunner<\/code><\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitExceptions&gt;java -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; JunitExceptionsTestRunner<\/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()\nI put in my bag: [Books, Notebooks, Pens]\nInside printItems()\nAll tests finished successfully...\n<\/code><\/pre>\n<p>As we see in the output, both tests finished successfully, although the second test case throws exception. The reason for this is that the thrown exception is the one declared in the <code>expected<\/code>, so the test doesn&#8217;t fail, it is just ignored.<\/p>\n<p>Now, let&#8217;s run the second test case <code>JunitExceptionsTest2.java<\/code>. We will make a small change in the code of <code>JunitExceptionsTestRunner.java<\/code>, so as to include the other class in <code>runClasses<\/code> method.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>JunitExceptionsTestRunner.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 JunitExceptionsTestRunner {\n\n\tpublic static void main(String[] args) {\n\n\t\tResult result = JUnitCore.runClasses(JunitExceptionsTest2.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}\n\t}\n}\n<\/pre>\n<p>In the same way as before, we compile and run our classes.<\/p>\n<ul>\n<li>Compile all java classes in <code>JUnitExceptions<\/code> directory.<\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitExceptions&gt;javac -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; FirstDayAtSchool.java JunitExceptionsTest1.java JunitExceptionsTest2.java JunitExceptionsTestRunner.java<\/pre>\n<ul>\n<li>Now run again the <code>JunitExceptionsTestRunner.<\/code><\/li>\n<\/ul>\n<pre class=\"brush:bash\">C:\\Users\\konstantina\\JUnitExceptions&gt;java -classpath \"C:\\Users\\konstantina\\Downloads\\junit-4.11.jar\";\"C:\\Users\\konstantina\\Downloads\\hamcrest-core-1.3.jar\"; JunitExceptionsTestRunner<\/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()\nI put in my bag: [Books, Notebooks, Pens]\nInside printItems()\ntestPrintItems(JunitExceptionsTest2): Unexpected exception, expected&lt;java.lang.ArithmeticException&gt; but was&lt;java.lang.ArrayIndexOutOfBoundsException&gt;<\/code><\/pre>\n<p>As we see in the output, the first test case succeeds but the second test case fails, as the exception of our code should be the <a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/lang\/ArrayIndexOutOfBoundsException.html\">ArrayIndexOutOfBoundsException<\/a> but the expected parameter declared <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/ArithmeticException.html\">ArithmeticException<\/a> as the expected exception.<\/p>\n<h2>Download the source code<\/h2>\n<p>This was an example of <code>expected<\/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\/JUnitExceptions.zip\">JUnitExceptions.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 expected 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 JUnitExceptions. 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-7582","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 Exceptions 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 expected 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-exceptions-test-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit Exceptions 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 expected in JUnit testing framework. Also, we will see\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-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-19T10:14:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-21T10:52:19+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=\"5 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-exceptions-test-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/\"},\"author\":{\"name\":\"Konstantina Dimtsa\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56\"},\"headline\":\"JUnit Exceptions Test Example\",\"datePublished\":\"2013-12-19T10:14:19+00:00\",\"dateModified\":\"2019-03-21T10:52:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/\"},\"wordCount\":628,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-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-exceptions-test-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/\",\"name\":\"JUnit Exceptions Test Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2013-12-19T10:14:19+00:00\",\"dateModified\":\"2019-03-21T10:52:19+00:00\",\"description\":\"In this example we are going to see how to use @Test annotation along with its optional parameter expected in JUnit testing framework. Also, we will see\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-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-exceptions-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 Exceptions 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 Exceptions Test Example - Java Code Geeks","description":"In this example we are going to see how to use @Test annotation along with its optional parameter expected 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-exceptions-test-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit Exceptions 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 expected in JUnit testing framework. Also, we will see","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-12-19T10:14:19+00:00","article_modified_time":"2019-03-21T10:52:19+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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/"},"author":{"name":"Konstantina Dimtsa","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5fc06d4d50814931c15af68106832a56"},"headline":"JUnit Exceptions Test Example","datePublished":"2013-12-19T10:14:19+00:00","dateModified":"2019-03-21T10:52:19+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/"},"wordCount":628,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-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-exceptions-test-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/","name":"JUnit Exceptions Test Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2013-12-19T10:14:19+00:00","dateModified":"2019-03-21T10:52:19+00:00","description":"In this example we are going to see how to use @Test annotation along with its optional parameter expected in JUnit testing framework. Also, we will see","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-test-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-exceptions-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-exceptions-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 Exceptions 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\/7582","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=7582"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/7582\/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=7582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=7582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=7582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}