{"id":47605,"date":"2017-06-19T11:00:06","date_gmt":"2017-06-19T08:00:06","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=47605"},"modified":"2019-03-20T13:51:20","modified_gmt":"2019-03-20T11:51:20","slug":"junit-dbunit-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/","title":{"rendered":"JUnit DbUnit Example"},"content":{"rendered":"<p>In this tutorial, we shall show users the usage of the DbUnit framework. JUnit DbUnit example will lead you to the details of testing with the DbUnit. There are other tutorials on JUnit if you want to learn more about the JUnit.<\/p>\n<p><a href=\"https:\/\/examples.javacodegeeks.com\/author\/vinod-kashyap\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><strong>Click here<\/strong><\/a> to view the tutorials related to JUnit on Java Code Geeks.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<h2>1. Introduction<\/h2>\n<p><a href=\"http:\/\/dbunit.sourceforge.net\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DbUnit<\/a> is a JUnit extension that helps to test the applications that are heavily dependent on the database.<\/p>\n<p>There are scenarios in which you have to test run all your test cases multiple times and the data comes from the database. In these scenarios, there are higher chances of corrupting the database. To handle this situation DbUnit comes into the picture. It helps us to generate the data from the database and then test those data. Thus avoiding the corrupting of the database.<\/p>\n<h2>2. Technology Stack<\/h2>\n<p>In this example, we will be using the following technologies:<\/p>\n<ul>\n<li><strong>Java 1.8<\/strong>&#8211; Language to write our application<\/li>\n<li><strong>JUnit 4.12<\/strong> &#8211; Testing framework<\/li>\n<li><strong>Maven<\/strong> &#8211; Build and dependency management tool<\/li>\n<li><strong>Eclipse<\/strong> &#8211; IDE for writing programs<\/li>\n<li><strong>DbUnit<\/strong> &#8211; Tool to test the database centric applications<\/li>\n<\/ul>\n<h2>3. Project Setup<\/h2>\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>Let&#8217;s start by creating a Maven project. Open Eclipse. Click on <strong>File -&gt; New -&gt; Maven Project<\/strong>.<br \/>\nFirstly, click on the first check box and then click <strong>Next<\/strong>.<\/p>\n<p><figure id=\"attachment_47616\" aria-describedby=\"caption-attachment-47616\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47616\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-1.jpg\" alt=\"JUnit DbUnit Example Setup 1\" width=\"725\" height=\"503\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-1.jpg 725w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-1-300x208.jpg 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><figcaption id=\"caption-attachment-47616\" class=\"wp-caption-text\">Figure 1: JUnit DbUnit Example Setup 1<\/figcaption><\/figure><\/p>\n<p>Secondly, fill in the details as shown and click <strong>Finish<\/strong>.<\/p>\n<p><figure id=\"attachment_47617\" aria-describedby=\"caption-attachment-47617\" style=\"width: 717px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-47617\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-2.jpg\" alt=\"JUnit DbUnit Example Setup 2\" width=\"717\" height=\"665\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-2.jpg 717w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/06\/junit-dbunit-setup-2-300x278.jpg 300w\" sizes=\"(max-width: 717px) 100vw, 717px\" \/><\/a><figcaption id=\"caption-attachment-47617\" class=\"wp-caption-text\">Figure 2: JUnit DbUnit Example Setup 2<\/figcaption><\/figure><\/p>\n<p>With this we are ready for the project. But this will only create a blank Maven project.<\/p>\n<h2>4. JUnit DbUnit Example<\/h2>\n<p>Let&#8217;s start coding our example. But before that, we need to do some initial steps for working of our example. We need to add the following lines to the <code>pom.xml<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:xml;wrap-lines:false;highlight:[3,10,16,30,31]\">&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;scope&gt;test&lt;\/scope&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n&lt;groupId&gt;org.dbunit&lt;\/groupId&gt;\n&lt;artifactId&gt;dbunit&lt;\/artifactId&gt;\n&lt;version&gt;2.5.3&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n&lt;groupId&gt;mysql&lt;\/groupId&gt;\n&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;\n&lt;version&gt;5.1.30&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n&lt;build&gt;\n&lt;finalName&gt;junitbasematcher&lt;\/finalName&gt;\n&lt;plugins&gt;\n&lt;plugin&gt;\n&lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\n&lt;version&gt;2.5.1&lt;\/version&gt;\n&lt;inherited&gt;true&lt;\/inherited&gt;\n&lt;configuration&gt;\n&lt;source&gt;1.8&lt;\/source&gt;\n&lt;target&gt;1.8&lt;\/target&gt;\n&lt;\/configuration&gt;\n&lt;\/plugin&gt;\n&lt;\/plugins&gt;\n&lt;\/build&gt;\n<\/pre>\n<p>Check lines <strong>3<\/strong>, <strong>10<\/strong> and <strong>16<\/strong>. We are initializing our applications with <strong>JUnit<\/strong>, <strong>DbUnit<\/strong> and <strong>MySql<\/strong> jar files.<\/p>\n<p>At line <strong>30<\/strong> and <strong>31<\/strong> we are telling Maven to use <strong>Java 8<\/strong> for this example. As such no exclusive feature of Java 8 is used in this example, we are targeting the latest version for more stability.<\/p>\n<h3>4.1 Java Classes<\/h3>\n<p>DbUnit provides the <code>DBTestCase<\/code> class that extends JUnit <code>TestCase<\/code> class. We can use this class and extend it to create out test class.<br \/>\nFirst of all, we need to create an XML file that will represent the database table.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>user.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;wrap-lines:false\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;dataset&gt;\n    &lt;USER userid='1' first_name='Vinod' last_name='Kashyap' \/&gt;\n\n    &lt;USER userid='2' first_name='Dhwani' last_name='Kashyap' \/&gt;\n\n    &lt;USER userid='3' first_name='Asmi' last_name='Kashyap' \/&gt;\n&lt;\/dataset&gt;\n<\/pre>\n<p>Here, <code>USER<\/code> is the name of the table. <code>userid<\/code>, <code>first_name<\/code> and <code>last_name<\/code> are column names. Make sure to put this file under the root so that it can be accessed from this class.<\/p>\n<p>Let&#8217;s start creating our test class.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>DbUnit.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[15,17,25,29,33,40]\"> \npackage junitdbunit;\n\nimport static org.hamcrest.CoreMatchers.is;\nimport static org.junit.Assert.assertThat;\n\nimport java.io.FileInputStream;\n\nimport org.dbunit.DBTestCase;\nimport org.dbunit.PropertiesBasedJdbcDatabaseTester;\nimport org.dbunit.dataset.IDataSet;\nimport org.dbunit.dataset.xml.FlatXmlDataSetBuilder;\nimport org.dbunit.operation.DatabaseOperation;\nimport org.junit.Test;\n\npublic class DbUnit extends DBTestCase {\n\n    public DbUnit(String name) {\n        super(name);\n        System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, \"com.mysql.jdbc.Driver\");\n        System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, \"jdbc:mysql:\/\/localhost:3306\/user\");\n        System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, \"root\");\n        System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, \"\");\n    }\n\n    protected IDataSet getDataSet() throws Exception {\n        return new FlatXmlDataSetBuilder().build(new FileInputStream(\"user.xml\"));\n    }\n\n    protected DatabaseOperation getSetUpOperation() throws Exception {\n        return DatabaseOperation.REFRESH;\n    }\n\n    protected DatabaseOperation getTearDownOperation() throws Exception {\n        return DatabaseOperation.NONE;\n    }\n\n    @Test\n    public void testById() {\n\n        int userId = 5;\/\/ get user id from database\n        assertThat(1, is(userId));\n    }\n}\n<\/pre>\n<p>Let&#8217;s analyze this class by identifying the main lines.<br \/>\n<strong>Line 15<\/strong>: As you can see, we have extended the <code>DBTestCase<\/code> class of the DbUnit. It will help us to take the help of some of the methods of the class.[ulp id=&#8217;ODQaBEw1BIbHApZq&#8217;]<\/p>\n<p><strong>Line 17<\/strong>: We have defined a class constructor that will initialize the required database connections. We have defined, a driver for the database to connect with the username and password to connect to it. We are also assigning the connection URL for the database.<\/p>\n<p><strong>Line 25<\/strong>: This method will read the XML file and create the required entries in the database. Here we are using the <code>FlatXmlDataSet<\/code> of <code>IDataSet<\/code>. Similarly there are many other structures that we can use. Some of them are:<\/p>\n<ul>\n<li>FlatXmlDataSet<\/li>\n<li>XmlDataSet<\/li>\n<li>StreamingDataSet<\/li>\n<li>DatabaseDataSet<\/li>\n<li>QueryDataSet<\/li>\n<li>DefaultDataSet<\/li>\n<li>CompositeDataSet<\/li>\n<li>FilteredDataSet<\/li>\n<li>XlsDataSet<\/li>\n<li>ReplacementDataSet<\/li>\n<\/ul>\n<p>You can visit <a href=\"http:\/\/dbunit.sourceforge.net\/components.html#dataset\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">this page<\/a> for more details about the above datasets.<\/p>\n<p><strong>Line 29<\/strong>: This method will setup database to initial position before testing any method.<\/p>\n<p><strong>Line 33<\/strong>: This will clear all the entries after test case run.<\/p>\n<p><strong>Line 40<\/strong>: At this line you have to fetch the record from the database and then test it with the <code>assertThat()<\/code> method.<\/p>\n<h2>5. Best Practices<\/h2>\n<p>As per the <a href=\"http:\/\/dbunit.sourceforge.net\/bestpractices.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DbUnit<\/a> there are some best practices to be followed while using the DbUnit. Here we include the DbUnit website for your reference.<\/p>\n<ol>\n<li><strong>Use one database instance per developer <\/strong>: Multiple developers working on the same project should have their own database instance to prevent data corruption<\/li>\n<li><strong>Good setup don&#8217;t need cleanup <\/strong>: You should always avoid creating tests that depends on results of preceding tests<\/li>\n<li><strong>Use multiple small datasets <\/strong>: instead of putting your entire database data in one large dataset, try to break it into many smaller chunks.<\/li>\n<li><strong>Perform setup of stale data once for entire test class or test suite <\/strong>: If several tests are using the same read-only data, this data could be initialized once for an entire test class or test suite<\/li>\n<\/ol>\n<h2>6. Conclusion<\/h2>\n<p>In this JUnit DbUnit example, you have learned the importance and usage of the DbUnit framework in the field of testing where the application is most of the time database centric.<\/p>\n<p>These applications are heavily dependent on the Database for work. DbUnit is an ideal framework for testing.<\/p>\n<h2>7. Download the Eclipse Project<\/h2>\n<p>This is a JUnit DbUnit 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\/06\/junitdbunit.zip\"><strong>junitdbunit.zip<\/strong><\/a><\/div>\n<h2>8. References<\/h2>\n<ul>\n<li><a href=\"http:\/\/dbunit.sourceforge.net\/apidocs\/index.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DbUnit JavaDoc<\/a><\/li>\n<li><a href=\"http:\/\/dbunit.sourceforge.net\/source-repository.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DbUnit Source Code<\/a><\/li>\n<li><a href=\"http:\/\/maven.apache.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Maven<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we shall show users the usage of the DbUnit framework. JUnit DbUnit example will lead you to the details of testing with the DbUnit. There are other tutorials on JUnit if you want to learn more about the JUnit. Click here to view the tutorials related to JUnit on Java Code Geeks. &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-47605","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 DbUnit Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.\" \/>\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-dbunit-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JUnit DbUnit Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-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-06-19T08:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-20T11:51:20+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-dbunit-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/\"},\"author\":{\"name\":\"Vinod Kumar Kashyap\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c\"},\"headline\":\"JUnit DbUnit Example\",\"datePublished\":\"2017-06-19T08:00:06+00:00\",\"dateModified\":\"2019-03-20T11:51:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/\"},\"wordCount\":853,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-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-dbunit-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/\",\"name\":\"JUnit DbUnit Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg\",\"datePublished\":\"2017-06-19T08:00:06+00:00\",\"dateModified\":\"2019-03-20T11:51:20+00:00\",\"description\":\"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-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-dbunit-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 DbUnit 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 DbUnit Example - Java Code Geeks","description":"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.","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-dbunit-example\/","og_locale":"en_US","og_type":"article","og_title":"JUnit DbUnit Example - Java Code Geeks","og_description":"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-06-19T08:00:06+00:00","article_modified_time":"2019-03-20T11:51:20+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-dbunit-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/"},"author":{"name":"Vinod Kumar Kashyap","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/1d6281e8235e49b5b8614621c2445d2c"},"headline":"JUnit DbUnit Example","datePublished":"2017-06-19T08:00:06+00:00","dateModified":"2019-03-20T11:51:20+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/"},"wordCount":853,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-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-dbunit-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/","name":"JUnit DbUnit Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/11\/junit-logo.jpg","datePublished":"2017-06-19T08:00:06+00:00","dateModified":"2019-03-20T11:51:20+00:00","description":"In this tutorial we shall show users the usage of DbUnit framework. JUnit DbUnit example will follow you to the details of testing with the DbUnit.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/junit\/junit-dbunit-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-dbunit-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 DbUnit 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\/47605","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=47605"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/47605\/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=47605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=47605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=47605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}