{"id":44529,"date":"2017-04-18T11:00:56","date_gmt":"2017-04-18T08:00:56","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=44529"},"modified":"2019-03-20T13:58:31","modified_gmt":"2019-03-20T11:58:31","slug":"junit-test-void-method-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/","title":{"rendered":"JUnit Test Void Method Example"},"content":{"rendered":"<p>In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit. In our previous tutorials, we have learned a lot about the JUnit and its various techniques about testing. But in our <a href=\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">previous tutorials<\/a> we haven&#8217;t seen how we can test <code>void<\/code> methods.<\/p>\n<p>You can read about <a href=\"http:\/\/junit.org\/junit4\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">JUnit<\/a> in <a href=\"https:\/\/www.amazon.in\/gp\/product\/1782166602\/ref=as_li_tl?ie=UTF8&amp;camp=3638&amp;creative=24630&amp;creativeASIN=1782166602&amp;linkCode=as2&amp;tag=vinodkashyap-21&amp;linkId=3cc2b3d303d19d11b02763a18b22f2bf\" target=\"_blank\" rel=\"noopener noreferrer\">Testing with JUnit<\/a><img decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"\/\/ir-in.amazon-adsystem.com\/e\/ir?t=vinodkashyap-21&amp;l=am2&amp;o=31&amp;a=1782166602\" alt=\"\" width=\"1\" height=\"1\" border=\"0\"> book.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<p>&nbsp;<br \/>\nIn this example, we will see how we can cover examples of some of the scenarios where we need to test the void methods. We will be using <a href=\"http:\/\/maven.apache.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Maven<\/a> as our build and dependency tool for this example.<\/p>\n<h2>1. Introduction<\/h2>\n<p>JUnit testing framework will help you test all your methods. It is a major tool in the arsenal of Java developers. We can test all type of methods irrespective of the method returning any value or not.<\/p>\n<p>In our <a href=\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">previous tutorials<\/a>, we have seen many ways to test the methods those returning the value. In this example <strong>we will test those methods that don&#8217;t return any value<\/strong>.<\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nIf your method has no side effects, and doesn&#8217;t return anything, then it&#8217;s not doing anything.<\/div>\n<p>Above line is from JUnit docs and tells everything about the methods.<\/p>\n<h2>2. Technologies Used<\/h2>\n<p>We will be using the following technologies in our example.<\/p>\n<ul>\n<li><strong>Java 1.8<\/strong>: Language to write our example. We will be using the latest Java version i.e. 1.8<\/li>\n<li><strong>JUnit 4.12<\/strong>: testing framework for unit testing.<\/li>\n<li><strong>Maven<\/strong>: build and dependency tool. It will be used to fetch the JUnit jar from maven repository.<\/li>\n<li><strong>Eclipse<\/strong>: IDE for writing code. You can use any IDE of your choice as it supports Maven integration<\/li>\n<\/ul>\n<h2>3. Project Setup<\/h2>\n<p>Let&#8217;s begin with creating our example.<\/p>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>Open eclipse. Click <strong>File -&gt; New -&gt; Maven Project<\/strong>.See below screen for modifications and click on <strong>Next<\/strong> button.<\/p>\n<p><figure id=\"attachment_44532\" aria-describedby=\"caption-attachment-44532\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44532\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-1.jpg\" alt=\"JUnit Test Void Method Example Setup 1\" width=\"725\" height=\"503\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-1.jpg 725w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-1-300x208.jpg 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><figcaption id=\"caption-attachment-44532\" class=\"wp-caption-text\">Figure 1: JUnit Test Void Method Example Setup 1<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>On next screen fill in all the details as shown below and click on the <strong>Finish<\/strong> button.<\/p>\n<p><figure id=\"attachment_44533\" aria-describedby=\"caption-attachment-44533\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44533\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-2.jpg\" alt=\"JUnit Test Void Method Example Setup 2\" width=\"725\" height=\"670\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-2.jpg 725w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-setup-2-300x277.jpg 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><figcaption id=\"caption-attachment-44533\" class=\"wp-caption-text\">Figure 2: JUnit Test Void Method Example Setup 2<\/figcaption><\/figure><\/p>\n<p>With this, we are ready with the blank Maven project. At this point, our example is an empty Maven project with a blank skeleton. Let&#8217;s start with our example from here. We need to write some initial steps before start coding.<\/p>\n<h2>4. JUnit Test Void Method Example<\/h2>\n<p>First of all we need to create the following lines in <code>pom.xml<\/code> file. These lines will fetch the JUnit dependency.<br \/>\nIt also tells Maven to use Java 1.8 for compiling our code.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;wrap-lines:false\">    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;junit&lt;\/groupId&gt;\n            &lt;artifactId&gt;junit&lt;\/artifactId&gt;\n            &lt;version&gt;4.12&lt;\/version&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n\n    &lt;properties&gt;\n        &lt;maven.compiler.source&gt;1.8&lt;\/maven.compiler.source&gt;\n        &lt;maven.compiler.target&gt;1.8&lt;\/maven.compiler.target&gt;\n    &lt;\/properties&gt;\n<\/pre>\n<h3>4.1 Java Classes<\/h3>\n<p>Now start by writing a java class that will prepare the core for our example. We will create a simple class which will be used later in this example for testing.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MyList.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[17]\">package junittestvoidmethod;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\n\npublic class MyList {\n\n    private List lstFruits = new ArrayList&lt;&gt;();\n\n    public void add(String fruit) {\n        lstFruits.add(fruit);\n    }\n\n    public void remove(String fruit) {\n        if (!lstFruits.contains(fruit)) {\n            throw new NoSuchElementException();\n        }\n        lstFruits.remove(fruit);\n    }\n\n    public int size() {\n        return lstFruits.size();\n    }\n\n    public void removeAll() {\n        lstFruits.clear();\n    }\n}\n\n<\/pre>\n<p>As you see in this class we have some void methods that need to be tested. This is a simple example explaining the behavior of the void methods. In this example, we are imitating the behavior of <code>List<\/code> interface for adding and removing of an element.<\/p>\n<p>We will simply create a <code>List<\/code> and then add and remove from that, but with help of our class.<br \/>\nAt <strong>line no 17<\/strong>, we are also throwing the <code>NoSuchElementException()<\/code>. We will also see how we can test this exception in our example. We have covered it here as it is thrown by the <code>void<\/code> method.<\/p>\n<h3>4.2 JUnit Test Class<\/h3>\n<p>Now, we will create a test class that will help and test our <code>MyList<\/code> class above. We will cover each test case in details. First of all lets see how our class will look like.[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MyListTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[16,23,28,30,34,40,46]\">package junittestvoidmethod;\n\nimport static org.junit.Assert.assertEquals;\n\nimport java.util.NoSuchElementException;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\npublic class MyListTest {\n\n    private MyList lstTest = new MyList();\n\n    @Before\n    public void init() {\n        lstTest.add(\"Apple\");\n        lstTest.add(\"Orange\");\n        lstTest.add(\"Grapes\");\n    }\n\n    @Test\n    public void testSize() {\n        assertEquals(\"Checking size of List\", 3, lstTest.size());\n    }\n\n    @Test\n    public void testAdd() {\n        lstTest.add(\"Banana\");\n        assertEquals(\"Adding 1 more fruit to list\", 4, lstTest.size());\n    }\n\n    @Test\n    public void testRemove() {\n        lstTest.remove(\"Orange\");\n        assertEquals(\"Removing 1 fruit from list\", 2, lstTest.size());\n    }\n\n    @Test(expected = NoSuchElementException.class)\n    public void testRemoveException() {\n        lstTest.remove(\"Kiwi\");\n        assertEquals(\"Removing 1 fruit from list\", 2, lstTest.size());\n    }\n\n    @After\n    public void destroy() {\n        lstTest.removeAll();\n    }\n}\n<\/pre>\n<h3>4.3 Code Explained<\/h3>\n<p>Let&#8217;s examine each method in details and how we are testing it.<\/p>\n<ul>\n<li><strong>init()<\/strong> is used to initialize the <code>List<\/code> of our class. We are adding some default elements, in our case fruits.<\/li>\n<li><strong>testSize()<\/strong> is used to check size of the list.<\/li>\n<li><strong>testAdd()<\/strong> is a <code>void<\/code> method. We are simply adding the new element to the existing list. This method is not returning any value. So the point is how we can test it? And the answer to this question is simple as that.<br \/>\nWe simply check the size of the list. If it is increased by one (as we added one element) then we can easily check the size.<br \/>\nWe have used the <code>assertEquals<\/code> here(<strong>see line no 30<\/strong>)<\/li>\n<li><strong>testRemove()<\/strong> is used to check the removal of an element from list. in this case, the size of the list should be decreased. Same way as in <code>testAdd()<\/code>, here also we are using <code>assertEquals<\/code> for testing.<\/li>\n<li><strong>testRemoveException()<\/strong> is used to test the exception thrown by the method. See how we have captured the exception. In this method we are removing an element which is not present in the list. In such case this method will thrown an exception. If we do not catch that exception, the test case will fail eventually.<br \/>\nSo to make our test case pass we have to catch it using the <code>@Test(expected = NoSuchElementException.class)<\/code>. It is a very clean way of catching exception and testing it.<\/li>\n<li><strong>destroy()<\/strong> is used to remove all elements that we have added to our collection. It is to be noted that <em><code>@Before<\/code> and <code>@After<\/code> will run before and after every test case<\/em>.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>Output<\/em><\/span><br \/>\nWe can analyze the output of our example in the JUnit tab of eclipse.<\/p>\n<p><figure id=\"attachment_44534\" aria-describedby=\"caption-attachment-44534\" style=\"width: 536px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-output.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44534\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-output.jpg\" alt=\"JUnit Test Void Method Example Output\" width=\"536\" height=\"262\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-output.jpg 536w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junit-test-void-method-example-output-300x147.jpg 300w\" sizes=\"(max-width: 536px) 100vw, 536px\" \/><\/a><figcaption id=\"caption-attachment-44534\" class=\"wp-caption-text\">Figure 3: JUnit Test Void Method Example Output<\/figcaption><\/figure><\/p>\n<h2>5. Conclusion<\/h2>\n<p>In this example, we have learned that how we can JUnit Test Void Method. We have also learned that how to catch the exception if it is thrown by a <code>void<\/code> method. Actually testing mechanism is same for all methods, but void methods are special as we don&#8217;t have any returning value to be matched for testing.<\/p>\n<p>But as we have previously said that the method may not be returning anything but it may be altering the behaviour of our program somewhere. So we simply test that case and then it is easy to implement it.<\/p>\n<h2>6. Download the Eclipse Project<\/h2>\n<p>This is a JUnit Test Void Method example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/junittestvoidmethod.zip\"><strong>JUnitTestVoidMethod.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit. In our previous tutorials, we have learned a lot about the JUnit and its various techniques about testing. But in our previous tutorials we haven&#8217;t &hellip;<\/p>\n","protected":false},"author":112,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-44529","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 Test Void Method Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.\" \/>\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-test-void-method-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit Test Void Method Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-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=\"2017-04-18T08:00:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-20T11:58:31+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=\"Vinod Kumar Kashyap\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vinodkashyap\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vinod Kumar Kashyap\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 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-test-void-method-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/\"},\"author\":{\"name\":\"Vinod Kumar Kashyap\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c\"},\"headline\":\"JUnit Test Void Method Example\",\"datePublished\":\"2017-04-18T08:00:56+00:00\",\"dateModified\":\"2019-03-20T11:58:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/\"},\"wordCount\":1048,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-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-test-void-method-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/\",\"name\":\"JUnit Test Void Method Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2017-04-18T08:00:56+00:00\",\"dateModified\":\"2019-03-20T11:58:31+00:00\",\"description\":\"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-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-test-void-method-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 Test Void Method 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\/1d6281e8235e49b5b8614621c2445d2c\",\"name\":\"Vinod Kumar Kashyap\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g\",\"caption\":\"Vinod Kumar Kashyap\"},\"description\":\"Vinod is Sun Certified and love to work in Java and related technologies. Having more than 13 years of experience, he had developed software's including technologies like Java, Hibernate, Struts, Spring, HTML 5, jQuery, CSS, Web Services, MongoDB, AngularJS, AWS. He is also a JUG Leader of Chandigarh Java User Group.\",\"sameAs\":[\"http:\/\/www.vinodkashyap.com\/\",\"https:\/\/www.instagram.com\/vinodkashyap\/\",\"https:\/\/in.linkedin.com\/in\/vinodkashyap\",\"https:\/\/in.pinterest.com\/vinodkashyap\/\",\"https:\/\/x.com\/vinodkashyap\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit Test Void Method Example - Java Code Geeks","description":"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.","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-test-void-method-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit Test Void Method Example - Java Code Geeks","og_description":"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-04-18T08:00:56+00:00","article_modified_time":"2019-03-20T11:58:31+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":"Vinod Kumar Kashyap","twitter_card":"summary_large_image","twitter_creator":"@vinodkashyap","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Vinod Kumar Kashyap","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/"},"author":{"name":"Vinod Kumar Kashyap","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c"},"headline":"JUnit Test Void Method Example","datePublished":"2017-04-18T08:00:56+00:00","dateModified":"2019-03-20T11:58:31+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/"},"wordCount":1048,"commentCount":4,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-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-test-void-method-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/","name":"JUnit Test Void Method Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2017-04-18T08:00:56+00:00","dateModified":"2019-03-20T11:58:31+00:00","description":"In this example, we shall show you to test void methods. In JUnit Test Void Method example we will learn how we can test the void methods using the JUnit.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-test-void-method-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-test-void-method-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 Test Void Method 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\/1d6281e8235e49b5b8614621c2445d2c","name":"Vinod Kumar Kashyap","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a11634ec460c849e8631b740af1b75cb68c9c58d5c2339c21bcd95f55b9af4f5?s=96&d=mm&r=g","caption":"Vinod Kumar Kashyap"},"description":"Vinod is Sun Certified and love to work in Java and related technologies. Having more than 13 years of experience, he had developed software's including technologies like Java, Hibernate, Struts, Spring, HTML 5, jQuery, CSS, Web Services, MongoDB, AngularJS, AWS. He is also a JUG Leader of Chandigarh Java User Group.","sameAs":["http:\/\/www.vinodkashyap.com\/","https:\/\/www.instagram.com\/vinodkashyap\/","https:\/\/in.linkedin.com\/in\/vinodkashyap","https:\/\/in.pinterest.com\/vinodkashyap\/","https:\/\/x.com\/vinodkashyap"],"url":"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44529","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\/112"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=44529"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44529\/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=44529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=44529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=44529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}