{"id":25162,"date":"2015-07-16T15:00:13","date_gmt":"2015-07-16T12:00:13","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=25162"},"modified":"2019-03-21T12:34:49","modified_gmt":"2019-03-21T10:34:49","slug":"junit-setup-teardown-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/","title":{"rendered":"JUnit SetUp \/ TearDown Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We needed them to be readily available when we create each of the method test cases and mock what was actually being used by the system at runtime.<\/p>\n<p>We can prepare this within the test method but what a good alternative is override the <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#setUp()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>setup<\/code><\/a> and <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#tearDown()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>tearDown<\/code><\/a> method. These methods will be called for each test case method calls. This will allow the test case to do a prepration and post clean up process for each of the JUnit method test call.\n<\/p>\n<h2>2. The Source Code(s)<\/h2>\n<p><span style=\"text-decoration: underline\"><em>JUnitTestCaseWOAnnotation.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jgc.areyes1.junit;\n\nimport com.jgc.areyes1.junit.obj.Account;\n\nimport junit.framework.TestCase;\n\npublic class JUnitTestCaseWOAnnotation extends TestCase {\n\t\n\tprivate AccountService accountService = new AccountService();\n\tprivate Account dummyAccount;\n\t\n\t\n\t@Override\n\tprotected void setUp() throws Exception {\n\t\tSystem.out.println(\"Setting it up!\");\n\t\tdummyAccount = accountService.getAccountDetails();\n\t}\n\t\n\tpublic void testDummyAccount() {\n\t\tSystem.out.println(\"Running: testDummyAccount\");\n\t\tassertNotNull(dummyAccount.getAccountCode());\n\t}\n\tpublic void testDummyAccountTransactions() {\n\t\tSystem.out.println(\"Running: testDummyAccountTransactions\");\n\t\tassertEquals(dummyAccount.getAccountTransactions().size(),3);\n\t}\n\t\n\t@Override\n\tprotected void tearDown() throws Exception {\n\t\tSystem.out.println(\"Running: tearDown\");\n\t\tdummyAccount = null;\n\t\tassertNull(dummyAccount);\n\t}\n\n}\n\n<\/pre>\n<p>First things first is, we need to override the TestCase object from the JUnit Test class. This will allow the compiler to tag the class as a JUnit Test case class and have a new set of overridable methods for us to modify the behaviour of our specific class. We override the <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#setUp()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>setup<\/code><\/a> and <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#tearDown()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>tearDown<\/code><\/a> method so that we can do the preparation as well as the clean up process for each test method available.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Here&#8217;s the output:<\/p>\n<p><figure id=\"attachment_25175\" aria-describedby=\"caption-attachment-25175\" style=\"width: 1074px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/1_wo.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25175\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/1_wo.jpg\" alt=\"Figure 1.0 JUnit Test case setup\/tearDown - non-annotation based approach\" width=\"1074\" height=\"488\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/1_wo.jpg 1074w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/1_wo-300x136.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/1_wo-1024x465.jpg 1024w\" sizes=\"(max-width: 1074px) 100vw, 1074px\" \/><\/a><figcaption id=\"caption-attachment-25175\" class=\"wp-caption-text\">Figure 1.0 JUnit Test case setup\/tearDown &#8211; non-annotation based approach<\/figcaption><\/figure><\/p>\n<p>The example above is actually the old way of doing test cases, the new more flexible way is by using annotations to tag the class as a JUnit Test case. We then use the <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Before.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>@Before<\/code><\/a> (<a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#setUp()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>setup<\/code><\/a>) and <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/After.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>@After<\/code><\/a> (<a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#tearDown()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>tearDown<\/code><\/a>) for our preparation and clean up. Here&#8217;s an example of the annotation based junit test case method.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JUnitTestCaseWAnnotation.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.jgc.areyes1.junit;\n\nimport org.junit.After;\nimport org.junit.Before;\nimport org.junit.Test;\n\nimport com.jgc.areyes1.junit.obj.Account;\n\nimport static org.junit.Assert.*;\n\npublic class JUnitTestCaseWAnnotation {\n\t\n\tprivate AccountService accountService = new AccountService();\n\tprivate Account dummyAccount;\n\t\n\t\n\t@Before \/\/ setup()\n\tpublic void before() throws Exception {\n\t\tSystem.out.println(\"Setting it up!\");\n\t\tdummyAccount = accountService.getAccountDetails();\n\t}\n\t\n\t@Test\n\tpublic void testDummyAccount() {\n\t\tSystem.out.println(\"Running: testDummyAccount\");\n\t\tassertNotNull(dummyAccount.getAccountCode());\n\t}\n\t@Test\n\tpublic void testDummyAccountTransactions() {\n\t\tSystem.out.println(\"Running: testDummyAccountTransactions\");\n\t\tassertEquals(dummyAccount.getAccountTransactions().size(),3);\n\t}\n\t\n\t@After \/\/ tearDown()\n\tpublic void after() throws Exception {\n\t\tSystem.out.println(\"Running: tearDown\");\n\t\tdummyAccount = null;\n\t\tassertNull(dummyAccount);\n\t}\n\n}\n\n<\/pre>\n<p>It utilises the <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/Before.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>@Before<\/code><\/a> and <a href=\"http:\/\/junit.sourceforge.net\/javadoc\/org\/junit\/After.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>@After<\/code><\/a> annotation for <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#setUp()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>setup<\/code><\/a> and <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#tearDown()\" target=\"_blank\" rel=\"noopener noreferrer\"><code>tearDown<\/code><\/a> method calls respectively.[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<p>Here&#8217;s the output:<\/p>\n<p><figure id=\"attachment_25176\" aria-describedby=\"caption-attachment-25176\" style=\"width: 1078px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/2_w.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25176\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/2_w.jpg\" alt=\"Figure 1.0 JUnit Test case setup\/tearDown - annotation based approach\" width=\"1078\" height=\"481\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/2_w.jpg 1078w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/2_w-300x134.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/2_w-1024x457.jpg 1024w\" sizes=\"(max-width: 1078px) 100vw, 1078px\" \/><\/a><figcaption id=\"caption-attachment-25176\" class=\"wp-caption-text\">Figure 1.0 JUnit Test case setup\/tearDown &#8211; annotation based approach<\/figcaption><\/figure><\/p>\n<h2>3. Download the Eclipse project<\/h2>\n<p>This was an example of JUnit <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#setUp()\" target=\"_blank\" rel=\"noopener noreferrer\">setup<\/a> and <a href=\"http:\/\/junit.sourceforge.net\/junit3.8.1\/javadoc\/junit\/framework\/TestCase.html#tearDown()\" target=\"_blank\" rel=\"noopener noreferrer\">tearDown<\/a>, that show cases it&#8217;s usage as well as the new annotation based alternatives.<\/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\/2015\/07\/junit-setupteardown-example.zip\"><strong>junit-setupteardown-example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We needed them to be readily available when we create each of the method test cases and mock what was actually being used by the system at runtime. We &hellip;<\/p>\n","protected":false},"author":41,"featured_media":6678,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[992,991,1032,989,990],"class_list":["post-25162","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-junit","tag-after","tag-before","tag-junit","tag-setup","tag-teardown"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JUnit SetUp \/ TearDown Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We\" \/>\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-setup-teardown-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit SetUp \/ TearDown Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-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:author\" content=\"https:\/\/www.facebook.com\/alvinjayreyes\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-16T12:00:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-21T10:34:49+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=\"Alvin Reyes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@alvinjayreyes\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alvin Reyes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 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-setup-teardown-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/\"},\"author\":{\"name\":\"Alvin Reyes\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d\"},\"headline\":\"JUnit SetUp \/ TearDown Example\",\"datePublished\":\"2015-07-16T12:00:13+00:00\",\"dateModified\":\"2019-03-21T10:34:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/\"},\"wordCount\":339,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"keywords\":[\"after\",\"before\",\"junit\",\"setup\",\"teardown\"],\"articleSection\":[\"junit\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/\",\"name\":\"JUnit SetUp \/ TearDown Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2015-07-16T12:00:13+00:00\",\"dateModified\":\"2019-03-21T10:34:49+00:00\",\"description\":\"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-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-setup-teardown-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 SetUp \/ TearDown 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\/b5bc005030b168a0a95f041b047bf82d\",\"name\":\"Alvin Reyes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg\",\"caption\":\"Alvin Reyes\"},\"description\":\"Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.\",\"sameAs\":[\"http:\/\/www.alvinjayreyes.com\",\"https:\/\/www.facebook.com\/alvinjayreyes\",\"http:\/\/ca.linkedin.com\/in\/alvinpreyes\",\"https:\/\/x.com\/alvinjayreyes\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/alvin-reyes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JUnit SetUp \/ TearDown Example - Java Code Geeks","description":"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We","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-setup-teardown-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit SetUp \/ TearDown Example - Java Code Geeks","og_description":"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/alvinjayreyes","article_published_time":"2015-07-16T12:00:13+00:00","article_modified_time":"2019-03-21T10:34:49+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":"Alvin Reyes","twitter_card":"summary_large_image","twitter_creator":"@alvinjayreyes","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Alvin Reyes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/"},"author":{"name":"Alvin Reyes","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b5bc005030b168a0a95f041b047bf82d"},"headline":"JUnit SetUp \/ TearDown Example","datePublished":"2015-07-16T12:00:13+00:00","dateModified":"2019-03-21T10:34:49+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/"},"wordCount":339,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","keywords":["after","before","junit","setup","teardown"],"articleSection":["junit"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/","name":"JUnit SetUp \/ TearDown Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2015-07-16T12:00:13+00:00","dateModified":"2019-03-21T10:34:49+00:00","description":"1. Introduction When we create JUnit test cases, we would normally setup our own configuration and data objects that can be used on our test cases. We","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-setup-teardown-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-setup-teardown-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 SetUp \/ TearDown 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\/b5bc005030b168a0a95f041b047bf82d","name":"Alvin Reyes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/01\/Alvin-Reyes-96x96.jpg","caption":"Alvin Reyes"},"description":"Alvin has an Information Technology Degree from Mapua Institute of Technology. During his studies, he was already heavily involved in a number of small to large projects where he primarily contributes by doing programming, analysis design. After graduating, he continued to do side projects on Mobile, Desktop and Web Applications.","sameAs":["http:\/\/www.alvinjayreyes.com","https:\/\/www.facebook.com\/alvinjayreyes","http:\/\/ca.linkedin.com\/in\/alvinpreyes","https:\/\/x.com\/alvinjayreyes"],"url":"https:\/\/examples.javacodegeeks.com\/author\/alvin-reyes\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25162","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\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=25162"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/25162\/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=25162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=25162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=25162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}